-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate from Tap to Jest (#220)
* feat: use jest to test i18next-scanner * chore: work in progress * test: migrating to jest * chore: update CLI and add missing dependencies * chore: exclude ./bin from linting * ci: remove redundant coverage script Co-authored-by: Cheton Wu <[email protected]>
- Loading branch information
Showing
22 changed files
with
3,909 additions
and
3,213 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
extends: 'trendmicro', | ||
parser: '@babel/eslint-parser', | ||
env: { | ||
browser: true, | ||
node: true, | ||
'jest/globals': true, | ||
}, | ||
plugins: [ | ||
'@babel', | ||
'jest', | ||
], | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules | ||
package-lock.json | ||
yarn.lock | ||
/.nyc_output | ||
/lib | ||
/output | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
module.exports = { | ||
module.exports = (api) => { | ||
const { env } = { ...api }; | ||
const plugins = [ | ||
]; | ||
|
||
if (typeof env === 'function' && env('test')) { | ||
// Enable async/await for jest | ||
plugins.push('@babel/plugin-transform-runtime'); | ||
} | ||
|
||
return { | ||
extends: '@trendmicro/babel-config', | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
useBuiltIns: 'entry', | ||
corejs: 3, | ||
} | ||
] | ||
] | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
useBuiltIns: 'entry', | ||
corejs: 3, | ||
} | ||
], | ||
[ | ||
'@babel/preset-react', | ||
{}, | ||
], | ||
], | ||
plugins, | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,75 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const program = require('commander'); | ||
const ensureArray = require('ensure-array'); | ||
const sort = require('gulp-sort'); | ||
const vfs = require('vinyl-fs'); | ||
const scanner = require('../lib'); | ||
const scanner = require('../lib').default; | ||
const pkg = require('../package.json'); | ||
|
||
program | ||
.version(pkg.version) | ||
.usage('[options] <file ...>') | ||
.option('--config <config>', 'Path to the config file (default: i18next-scanner.config.js)', 'i18next-scanner.config.js') | ||
.option('--output <path>', 'Path to the output directory (default: .)'); | ||
.version(pkg.version) | ||
.usage('[options] <file ...>') | ||
.option('--config <config>', 'Path to the config file (default: i18next-scanner.config.js)', 'i18next-scanner.config.js') | ||
.option('--output <path>', 'Path to the output directory (default: .)'); | ||
|
||
program.on('--help', function() { | ||
console.log(''); | ||
console.log(' Examples:'); | ||
console.log(''); | ||
console.log(' $ i18next-scanner --config i18next-scanner.config.js --output /path/to/output \'src/**/*.{js,jsx}\''); | ||
console.log(' $ i18next-scanner --config i18next-scanner.config.js "src/**/*.{js,jsx}"'); | ||
console.log(' $ i18next-scanner "/path/to/src/app.js" "/path/to/assets/index.html"'); | ||
console.log(''); | ||
program.on('--help', () => { | ||
console.log(''); | ||
console.log(' Examples:'); | ||
console.log(''); | ||
console.log(' $ i18next-scanner --config i18next-scanner.config.js --output /path/to/output \'src/**/*.{js,jsx}\''); | ||
console.log(' $ i18next-scanner --config i18next-scanner.config.js "src/**/*.{js,jsx}"'); | ||
console.log(' $ i18next-scanner "/path/to/src/app.js" "/path/to/assets/index.html"'); | ||
console.log(''); | ||
}); | ||
|
||
program.parse(process.argv); | ||
|
||
if (!program.config) { | ||
program.help(); | ||
return; | ||
const options = program.opts(); | ||
|
||
if (!options.config) { | ||
program.help(); | ||
process.exit(1); | ||
} | ||
|
||
let config = {}; | ||
try { | ||
config = require(path.resolve(program.config)); | ||
// eslint-disable-next-line import/no-dynamic-require | ||
config = require(path.resolve(options.config)); | ||
} catch (err) { | ||
console.error('i18next-scanner:', err); | ||
return; | ||
console.error('i18next-scanner:', err); | ||
process.exit(1); | ||
} | ||
|
||
{ // Input | ||
config.input = (program.args.length > 0) ? program.args : ensureArray(config.input); | ||
config.input = config.input.map(function(s) { | ||
s = s.trim(); | ||
|
||
// On Windows, arguments contain spaces must be enclosed with double quotes, not single quotes. | ||
if (s.match(/(^'.*'$|^".*"$)/)) { | ||
// Remove first and last character | ||
s = s.slice(1, -1); | ||
} | ||
return s; | ||
}); | ||
config.input = (program.args.length > 0) ? program.args : ensureArray(config.input); | ||
config.input = config.input.map((s) => { | ||
s = s.trim(); | ||
|
||
if (config.input.length === 0) { | ||
program.help(); | ||
return; | ||
// On Windows, arguments contain spaces must be enclosed with double quotes, not single quotes. | ||
if (s.match(/(^'.*'$|^".*"$)/)) { | ||
// Remove first and last character | ||
s = s.slice(1, -1); | ||
} | ||
return s; | ||
}); | ||
|
||
if (config.input.length === 0) { | ||
program.help(); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
{ // Output | ||
config.output = program.output || config.output; | ||
config.output = options.output || config.output; | ||
|
||
if (!config.output) { | ||
config.output = '.'; | ||
} | ||
if (!config.output) { | ||
config.output = '.'; | ||
} | ||
} | ||
|
||
vfs.src(config.input) | ||
.pipe(sort()) // Sort files in stream by path | ||
.pipe(scanner(config.options, config.transform, config.flush)) | ||
.pipe(vfs.dest(config.output)) | ||
.pipe(sort()) // Sort files in stream by path | ||
.pipe(scanner(config.options, config.transform, config.flush)) | ||
.pipe(vfs.dest(config.output)); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom'; |
This file contains 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
This file contains 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
Oops, something went wrong.