Created
August 6, 2021 10:26
-
-
Save thanhtunguet/91512e80d806cf15d001bf0db4d89938 to your computer and use it in GitHub Desktop.
Generate SCSS mocks for Jest
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
const fs = require('fs'); | |
const {join} = require('path'); | |
function readDirAll(path, files = []) { | |
if (fs.lstatSync(path).isDirectory()) { | |
fs.readdirSync(path).forEach((entry) => { | |
if (entry !== '.' && entry !== '..') { | |
readDirAll(join(path, entry), files); | |
} | |
}); | |
return files; | |
} | |
if (path.match(/\.scss/)) { | |
files.push(path); | |
} | |
return files; | |
} | |
const files = []; | |
readDirAll('src', files); | |
let content = ''; | |
files.forEach((element) => { | |
content += ` | |
jest.mock( | |
'${element}', | |
() => ({}), | |
);`; | |
}); | |
fs.writeFileSync('__mocks__/styles.mock.ts', content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment