-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A CLI for running specific tests suites, like bootstrap CLI #1752
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e7660ac
WIP
ndelangen 45476de
ADD CLI for running tests, supports jest-projects and passing params …
ndelangen 6190aca
ADD some jest arguments
ndelangen b64af7b
CHANGE docs (CONTRIBUTIONS) to reflect changed to test script && CHAN…
ndelangen cfccd65
Yarn on CI
ndelangen 5b3aa41
Use `yarn install` everywhere over the shorthand
ndelangen 3a3658d
CHANGE CONTRIBUTING.md to say yarn run publish
ndelangen a8f7942
Merge branch 'release/3.3' into ndelangen/testing-cli
Hypnosphi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,145 @@ | ||
#!/usr/bin/env node | ||
const inquirer = require('inquirer'); | ||
const program = require('commander'); | ||
const childProcess = require('child_process'); | ||
const chalk = require('chalk'); | ||
const log = require('npmlog'); | ||
|
||
log.heading = 'storybook'; | ||
const prefix = 'test'; | ||
log.addLevel('aborted', 3001, { fg: 'red', bold: true }); | ||
|
||
const spawn = command => | ||
childProcess.spawnSync(`${command}`, { | ||
shell: true, | ||
stdio: 'inherit', | ||
}); | ||
|
||
const main = program.version('3.0.0').option('--all', `Test everything ${chalk.gray('(all)')}`); | ||
|
||
const createProject = ({ defaultValue, option, name, projectLocation }) => ({ | ||
value: false, | ||
defaultValue: defaultValue || false, | ||
option: option || undefined, | ||
name: name || 'unnamed task', | ||
projectLocation, | ||
}); | ||
const createOption = ({ defaultValue, option, name, extraParam }) => ({ | ||
value: false, | ||
defaultValue: defaultValue || false, | ||
option: option || undefined, | ||
name: name || 'unnamed task', | ||
extraParam, | ||
}); | ||
|
||
const tasks = { | ||
core: createProject({ | ||
name: `Core & React & Vue ${chalk.gray('(core)')}`, | ||
defaultValue: true, | ||
option: '--core', | ||
projectLocation: './', | ||
}), | ||
'react-native-vanilla': createProject({ | ||
name: `React-Native example ${chalk.gray('(react-native-vanilla)')}`, | ||
defaultValue: true, | ||
option: '--reactnative', | ||
projectLocation: './examples/react-native-vanilla', | ||
}), | ||
// 'crna-kitchen-sink': createProject({ | ||
// name: `React-Native-App example ${chalk.gray('(crna-kitchen-sink)')} ${chalk.red( | ||
// '[not implemented yet]' | ||
// )}`, | ||
// defaultValue: false, | ||
// option: '--reactnativeapp', | ||
// projectLocation: './examples/crna-kitchen-sink', | ||
// }), | ||
watchmode: createOption({ | ||
name: `Run in watch-mode ${chalk.gray('(watchmode)')}`, | ||
defaultValue: false, | ||
option: '--watch', | ||
extraParam: '--watch', | ||
}), | ||
coverage: createOption({ | ||
name: `Output coverage reports ${chalk.gray('(coverage)')}`, | ||
defaultValue: false, | ||
option: '--coverage', | ||
extraParam: '--coverage', | ||
}), | ||
runInBand: createOption({ | ||
name: `Run all tests serially in the current process ${chalk.gray('(runInBand)')}`, | ||
defaultValue: false, | ||
option: '--runInBand', | ||
extraParam: '--runInBand', | ||
}), | ||
}; | ||
|
||
const getProjects = list => { | ||
const filtered = list.filter(key => key.projectLocation); | ||
if (filtered.length > 0) { | ||
return filtered.map(key => key.projectLocation); | ||
} | ||
|
||
// if list would have been empty, we run with default projects | ||
return Object.keys(tasks) | ||
.map(key => tasks[key]) | ||
.filter(key => key.projectLocation && key.defaultValue) | ||
.map(key => key.projectLocation); | ||
}; | ||
|
||
const getExtraParams = list => list.filter(key => key.extraParam).map(key => key.extraParam); | ||
|
||
Object.keys(tasks) | ||
.reduce((acc, key) => acc.option(tasks[key].option, tasks[key].name), main) | ||
.parse(process.argv); | ||
|
||
Object.keys(tasks).forEach(key => { | ||
tasks[key].value = | ||
program[tasks[key].option.replace('--', '')] || (program.all && tasks[key].projectLocation); | ||
}); | ||
|
||
let selection; | ||
if (!Object.keys(tasks).map(key => tasks[key].value).filter(Boolean).length) { | ||
selection = inquirer | ||
.prompt([ | ||
{ | ||
type: 'checkbox', | ||
message: 'Select which tests to run', | ||
name: 'todo', | ||
choices: Object.keys(tasks) | ||
.map(key => tasks[key]) | ||
.filter(key => key.projectLocation) | ||
.map(key => ({ | ||
name: key.name, | ||
checked: key.defaultValue, | ||
})) | ||
.concat(new inquirer.Separator()) | ||
.concat( | ||
Object.keys(tasks).map(key => tasks[key]).filter(key => key.extraParam).map(key => ({ | ||
name: key.name, | ||
checked: key.defaultValue, | ||
})) | ||
), | ||
}, | ||
]) | ||
.then(({ todo }) => | ||
todo.map(name => tasks[Object.keys(tasks).find(i => tasks[i].name === name)]) | ||
); | ||
} else { | ||
selection = Promise.resolve( | ||
Object.keys(tasks).map(key => tasks[key]).filter(item => item.value === true) | ||
); | ||
} | ||
|
||
selection | ||
.then(list => { | ||
if (list.length === 0) { | ||
log.warn(prefix, 'Nothing to test'); | ||
} else { | ||
spawn(`jest --projects ${getProjects(list).join(' ')} ${getExtraParams(list).join(' ')}`); | ||
process.stdout.write('\x07'); | ||
} | ||
}) | ||
.catch(e => { | ||
log.aborted(prefix, chalk.red(e.message)); | ||
log.silly(prefix, e); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @Hypnosphi opted to use the shorthand
yarn
notation. We should keep it consistent