-
Notifications
You must be signed in to change notification settings - Fork 73
Selective test on workspace name with the --package option #2145
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
0a73fdc
2f64ea3
1cb6c0f
f490d73
086a088
98f82ed
2d649a4
0111c22
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,5 @@ | ||
| --- | ||
| "modular-scripts": minor | ||
| --- | ||
|
|
||
| Selective test on workspace name with the --package option |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,209 @@ describe('Modular test command', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('test command can successfully do selective tests based on selected packages', () => { | ||
| const fixturesFolder = path.join( | ||
| __dirname, | ||
| Array.from({ length: 4 }).reduce<string>( | ||
| (acc) => `${acc}..${path.sep}`, | ||
| '', | ||
| ), | ||
| '__fixtures__', | ||
| 'ghost-testing', | ||
| ); | ||
|
|
||
| const currentModularFolder = getModularRoot(); | ||
| let randomOutputFolder: string; | ||
|
|
||
| beforeEach(() => { | ||
| // Create random dir | ||
| randomOutputFolder = tmp.dirSync({ unsafeCleanup: true }).name; | ||
| fs.copySync(fixturesFolder, randomOutputFolder); | ||
| execa.sync('yarn', { | ||
| cwd: randomOutputFolder, | ||
| }); | ||
| }); | ||
|
|
||
| // Run in a single test, serially for performance reasons (the setup time is quite long) | ||
| it('finds --package after specifying a valid workspaces / finds ancestors using --ancestors', () => { | ||
| const resultPackages = runRemoteModularTest( | ||
| currentModularFolder, | ||
| randomOutputFolder, | ||
| ['test', '--package', 'b', '--package', 'c'], | ||
| ); | ||
| expect(resultPackages.stderr).toContain( | ||
| 'packages/c/src/__tests__/utils/c-nested.test.ts', | ||
| ); | ||
| expect(resultPackages.stderr).toContain( | ||
| 'packages/c/src/__tests__/c.test.ts', | ||
| ); | ||
| expect(resultPackages.stderr).toContain( | ||
| 'packages/b/src/__tests__/utils/b-nested.test.ts', | ||
| ); | ||
| expect(resultPackages.stderr).toContain( | ||
| 'packages/b/src/__tests__/b.test.ts', | ||
| ); | ||
|
|
||
| const resultPackagesWithAncestors = runRemoteModularTest( | ||
| currentModularFolder, | ||
| randomOutputFolder, | ||
| ['test', '--ancestors', '--package', 'b', '--package', 'c'], | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could maybe use a single
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmh, not sure what you mean - it's not possible to pass an array to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless you're saying that we can conflate
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the shape of |
||
| 'packages/c/src/__tests__/utils/c-nested.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/c/src/__tests__/c.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/b/src/__tests__/utils/b-nested.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/b/src/__tests__/b.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/a/src/__tests__/utils/a-nested.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/a/src/__tests__/a.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/e/src/__tests__/utils/e-nested.test.ts', | ||
| ); | ||
| expect(resultPackagesWithAncestors.stderr).toContain( | ||
| 'packages/e/src/__tests__/e.test.ts', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('test command has error states', () => { | ||
| // Run in a single test, serially for performance reasons (the setup time is quite long) | ||
| it('errors when specifying --package with --changed', async () => { | ||
| let errorNumber; | ||
| try { | ||
| await execa( | ||
| 'yarnpkg', | ||
| ['modular', 'test', '--changed', '--package', 'modular-scripts'], | ||
| { | ||
| all: true, | ||
| cleanup: true, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| errorNumber = (error as ExecaError).exitCode; | ||
| } | ||
| expect(errorNumber).toEqual(1); | ||
| }); | ||
|
|
||
| it('errors when specifying --package with a non-existing workspace', async () => { | ||
| let capturedError; | ||
| try { | ||
| await execa( | ||
| 'yarnpkg', | ||
| ['modular', 'test', '--package', 'non-existing'], | ||
| { | ||
| all: true, | ||
| cleanup: true, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| capturedError = error as ExecaError; | ||
| } | ||
| expect(capturedError?.exitCode).toEqual(1); | ||
| expect(capturedError?.stderr).toContain( | ||
| `Package non-existing was specified, but Modular couldn't find it`, | ||
| ); | ||
| }); | ||
|
|
||
| it('errors when specifying a regex with --packages', async () => { | ||
| let capturedError; | ||
| try { | ||
| await execa( | ||
| 'yarnpkg', | ||
| [ | ||
| 'modular', | ||
| 'test', | ||
| 'memoize.test.ts', | ||
| '--package', | ||
| 'modular-scripts', | ||
| ], | ||
| { | ||
| all: true, | ||
| cleanup: true, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| capturedError = error as ExecaError; | ||
| } | ||
| expect(capturedError?.exitCode).toEqual(1); | ||
| expect(capturedError?.stderr).toContain( | ||
| `Option --package conflicts with supplied test regex`, | ||
| ); | ||
| }); | ||
|
|
||
| it('errors when specifying a regex with --package', async () => { | ||
| let capturedError; | ||
| try { | ||
| await execa( | ||
| 'yarnpkg', | ||
| [ | ||
| 'modular', | ||
| 'test', | ||
| 'memoize.test.ts', | ||
| '--package', | ||
| 'modular-scripts', | ||
| ], | ||
| { | ||
| all: true, | ||
| cleanup: true, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| capturedError = error as ExecaError; | ||
| } | ||
| expect(capturedError?.exitCode).toEqual(1); | ||
| expect(capturedError?.stderr).toContain( | ||
| `Option --package conflicts with supplied test regex`, | ||
| ); | ||
| }); | ||
|
|
||
| it('errors when specifying a regex with --changed', async () => { | ||
| let capturedError; | ||
| try { | ||
| await execa( | ||
| 'yarnpkg', | ||
| ['modular', 'test', 'memoize.test.ts', '--changed'], | ||
| { | ||
| all: true, | ||
| cleanup: true, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| capturedError = error as ExecaError; | ||
| } | ||
| expect(capturedError?.exitCode).toEqual(1); | ||
| expect(capturedError?.stderr).toContain( | ||
| `Option --changed conflicts with supplied test regex`, | ||
| ); | ||
| }); | ||
|
|
||
| it('errors when specifying --compareBranch without --changed', async () => { | ||
| let capturedError; | ||
| try { | ||
| await execa('yarnpkg', ['modular', 'test', '--compareBranch', 'main'], { | ||
| all: true, | ||
| cleanup: true, | ||
| }); | ||
| } catch (error) { | ||
| capturedError = error as ExecaError; | ||
| } | ||
| expect(capturedError?.exitCode).toEqual(1); | ||
| expect(capturedError?.stderr).toContain( | ||
| `Option --compareBranch doesn't make sense without option --changed`, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function runRemoteModularTest( | ||
|
|
||
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.
Also a typo?
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.
Maybe not. I'm confused - are they workspaces or packages? In my mind, a workspace can consist of many packages (the workspace usually means the
packagesdir, if talking in yarn languge)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.
It's incredibly confusing, but it seems that any package that falls in the
workspacesglob / array in the manifest is called a "workspace": https://classic.yarnpkg.com/lang/en/docs/workspaces/