-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add tests for command "run" #821
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* @flow */ | ||
|
|
||
| import {run} from '../../src/cli/commands/run.js'; | ||
| import * as reporters from '../../src/reporters/index.js'; | ||
| import Config from '../../src/config.js'; | ||
|
|
||
| jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; | ||
|
|
||
| const path = require('path'); | ||
|
|
||
| const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'run'); | ||
|
|
||
| jest.mock('../../src/util/execute-lifecycle-script'); | ||
| const executeLifecycleScript = (require('../../src/util/execute-lifecycle-script').default: $FlowFixMe); | ||
|
|
||
| async function runRun( | ||
| flags: Object, | ||
| args: Array<string>, | ||
| name: string, | ||
| ): Promise<Config> { | ||
| const cwd = path.join(fixturesLoc, name); | ||
| const reporter = new reporters.NoopReporter(); | ||
| const config = new Config(reporter); | ||
| await config.init({cwd}); | ||
| await run(config, reporter, flags, args); | ||
| return config; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| executeLifecycleScript.mockClear(); | ||
| }); | ||
|
|
||
| it('run should run script', async (): Promise<void> => { | ||
| const config = await runRun({}, ['some-script'], 'run-should-run-script'); | ||
|
|
||
| const expectedCall = [ | ||
| 'some-script', | ||
| config, | ||
| config.cwd, | ||
| `echo success `, | ||
| ]; | ||
|
|
||
| expect(executeLifecycleScript.mock.calls.length).toEqual(1); | ||
| expect(executeLifecycleScript).toBeCalledWith(...expectedCall); | ||
| }); | ||
|
|
||
| it('run should run binary', async (): Promise<void> => { | ||
| const config = await runRun({}, ['some-binary'], 'run-should-run-binary'); | ||
|
|
||
| const expectedCall = [ | ||
| 'some-binary', | ||
| config, | ||
| config.cwd, | ||
| `"${path.join(config.cwd, 'node_modules/.bin/some-binary')}" `, | ||
| ]; | ||
|
|
||
| expect(executeLifecycleScript.mock.calls.length).toEqual(1); | ||
| expect(executeLifecycleScript).toBeCalledWith(...expectedCall); | ||
| }); | ||
|
|
||
| it('run should run binary with args', async (): Promise<void> => { | ||
| const config = await runRun({}, ['some-binary', '--test-arg'], 'run-should-run-binary-with-args'); | ||
|
|
||
| const expectedCall = [ | ||
| 'some-binary', | ||
| config, | ||
| config.cwd, | ||
| `"${path.join(config.cwd, 'node_modules/.bin/some-binary')}" --test-arg`, | ||
| ]; | ||
|
|
||
| expect(executeLifecycleScript.mock.calls.length).toEqual(1); | ||
| expect(executeLifecycleScript).toBeCalledWith(...expectedCall); | ||
| }); | ||
|
|
||
| it('run should run binary with space in path', async (): Promise<void> => { | ||
| const config = await runRun({}, ['some-binary'], 'run should run binary with space in path'); | ||
|
|
||
| const expectedCall = [ | ||
| 'some-binary', | ||
| config, | ||
| config.cwd, | ||
| `"${path.join(config.cwd, 'node_modules/.bin/some-binary')}" `, | ||
| ]; | ||
|
|
||
| expect(executeLifecycleScript.mock.calls.length).toEqual(1); | ||
| expect(executeLifecycleScript).toBeCalledWith(...expectedCall); | ||
| }); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
|
|
||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
|
|
||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "scripts": { | ||
| "some-script": "echo success" | ||
| } | ||
| } |
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.
Oh, I see what this is doing! If you do this, and add specs for the same thing but with spaces in the fixture directory name, that should have you covering the issue #633 intended to fix completely! 😃
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.
Yup, the rest should be just copy&paste. I just want to be sure that I am on the right path. Currently only "add", "install" and "self-update" commands are tested so there isn't much to use as an example.
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.
Come to think of it, it could be reasonable to mock out
child_process(used all the way over here) for these purposes, but I guess it depends if you want to actually integration test with the shell.