Last active
February 4, 2018 22:30
-
-
Save anteriovieira/961458731db5721b962951649f6b2980 to your computer and use it in GitHub Desktop.
Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear() | |
const {lstatSync, readdirSync, writeFileSync, unlinkSync} = require('fs') | |
const glob = require('glob') | |
const {join} = require('path') | |
const isDirectory = source => lstatSync(source).isDirectory | |
const getDirectories = source => | |
readdirSync(source).map(name => join(source, name)).filter(isDirectory) | |
const directories = getDirectories('./') | |
for (directory of directories) { | |
glob(`./${directory}/*.vue`, null, (er, files) => { | |
for (file of files) { | |
let filename = file.replace(/^\.\//, '').replace(/\.(vue)$/, '') | |
let [dir, name] = filename.split('/') | |
let component = `B${name}` | |
let template = | |
`import { shallow } from '@vue/test-utils' | |
import ${component} from '@components/${filename}' | |
describe('${component}', () => { | |
it('Is called', () => { | |
const wrapper = shallow(${component}) | |
expect(wrapper.name()).toBe('${component}') | |
}) | |
}) | |
` | |
let newfileSpec = `./${filename}.spec.js` | |
writeFileSync(newfileSpec, template, (er) => { | |
if (er) { | |
console.log('Error: ', er) | |
return | |
} | |
console.log(`Spect ${fileSpec} created`) | |
}) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment