diff --git a/e2e/cache.test.ts b/e2e/cache.test.ts deleted file mode 100644 index 5dd583f052..0000000000 --- a/e2e/cache.test.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { - ensureProject, - forEachCli, - listFiles, - rmDist, - runCLI, - runCommand, - uniq, - updateFile -} from './utils'; - -forEachCli(() => { - describe('Cache', () => { - it('should not use cache when it is not enabled', async () => { - ensureProject(); - - const myapp1 = uniq('myapp1'); - const myapp2 = uniq('myapp2'); - runCLI(`generate @nrwl/web:app ${myapp1}`); - runCLI(`generate @nrwl/web:app ${myapp2}`); - const files = `--files="apps/${myapp1}/src/main.ts,apps/${myapp2}/src/main.ts"`; - - // run without caching - // -------------------------------------------- - const outputWithoutCachingEnabled1 = runCommand( - `npm run affected:build -- ${files}` - ); - const filesApp1 = listFiles(`dist/apps/${myapp1}`); - const filesApp2 = listFiles(`dist/apps/${myapp2}`); - - expect(outputWithoutCachingEnabled1).not.toContain( - 'read the output from cache' - ); - - const outputWithoutCachingEnabled2 = runCommand( - `npm run affected:build -- ${files}` - ); - expect(outputWithoutCachingEnabled2).not.toContain( - 'read the output from cache' - ); - - // enable caching - // -------------------------------------------- - updateFile('nx.json', c => { - const nxJson = JSON.parse(c); - nxJson.tasksRunnerOptions = { - default: { - runner: '@nrwl/workspace/src/tasks-runner/tasks-runner-v2', - options: { - cacheableOperations: ['build', 'lint'] - } - } - }; - return JSON.stringify(nxJson, null, 2); - }); - - // run build with caching - // -------------------------------------------- - const outputThatPutsDataIntoCache = runCommand( - `npm run affected:build -- ${files}` - ); - // now the data is in cache - expect(outputThatPutsDataIntoCache).not.toContain( - 'read the output from cache' - ); - - rmDist(); - - const outputWithBothBuildTasksCached = runCommand( - `npm run affected:build -- ${files}` - ); - expect(outputWithBothBuildTasksCached).toContain( - 'read the output from cache' - ); - expectCached(outputWithBothBuildTasksCached, [myapp1, myapp2]); - expect(listFiles(`dist/apps/${myapp1}`)).toEqual(filesApp1); - expect(listFiles(`dist/apps/${myapp2}`)).toEqual(filesApp2); - - // touch myapp1 - // -------------------------------------------- - updateFile(`apps/${myapp1}/src/main.ts`, c => { - return `${c}\n//some comment`; - }); - const outputWithBuildApp2Cached = runCommand( - `npm run affected:build -- ${files}` - ); - expect(outputWithBuildApp2Cached).toContain('read the output from cache'); - expectCached(outputWithBuildApp2Cached, [myapp2]); - - // touch package.json - // -------------------------------------------- - updateFile(`package.json`, c => { - const r = JSON.parse(c); - r.description = 'different'; - return JSON.stringify(r); - }); - const outputWithNoBuildCached = runCommand( - `npm run affected:build -- ${files}` - ); - expect(outputWithNoBuildCached).not.toContain( - 'read the output from cache' - ); - - // run lint with caching - // -------------------------------------------- - const outputWithNoLintCached = runCommand( - `npm run affected:lint -- ${files}` - ); - expect(outputWithNoLintCached).not.toContain( - 'read the output from cache' - ); - - const outputWithBothLintTasksCached = runCommand( - `npm run affected:lint -- ${files}` - ); - expect(outputWithBothLintTasksCached).toContain( - 'read the output from cache' - ); - expectCached(outputWithBothLintTasksCached, [ - myapp1, - myapp2, - `${myapp1}-e2e`, - `${myapp2}-e2e` - ]); - }, 120000); - }); - - function expectCached(actual: string, expected: string[]) { - const section = actual.split('read the output from cache')[1]; - const r = section - .split('\n') - .filter(l => l.trim().startsWith('-')) - .map(l => l.split('- ')[1].trim()); - r.sort((a, b) => a.localeCompare(b)); - expected.sort((a, b) => a.localeCompare(b)); - expect(r).toEqual(expected); - } -}); diff --git a/e2e/default-tasks-runner.test.ts b/e2e/default-tasks-runner.test.ts new file mode 100644 index 0000000000..e185e1973d --- /dev/null +++ b/e2e/default-tasks-runner.test.ts @@ -0,0 +1,166 @@ +import { + ensureProject, + forEachCli, + listFiles, + rmDist, + runCLI, + runCommand, + uniq, + updateFile +} from './utils'; + +forEachCli(() => { + describe('defaultTasksRunner', () => { + describe('Parallel', () => { + it('should be able to run tasks in parallel', () => { + ensureProject(); + + const mylib1 = uniq('mylib1'); + const mylib2 = uniq('mylib1'); + runCLI(`generate @nrwl/workspace:lib ${mylib1}`); + runCLI(`generate @nrwl/workspace:lib ${mylib2}`); + + const files = `--files="libs/${mylib1}/src/index.ts,libs/${mylib2}/src/index.ts"`; + const output = runCommand( + `npm run affected:test -- ${files} --parallel` + ); + + const startTestingLib1 = output.indexOf(`"test" "${mylib1}"`); + const startTestingLib2 = output.indexOf(`"test" "${mylib2}"`); + + const stopTesting = output.indexOf(`No tests found`); + + expect(startTestingLib1).toBeLessThan(stopTesting); + expect(startTestingLib2).toBeLessThan(stopTesting); + }); + }); + + describe('Cache', () => { + it('should not use cache when it is not enabled', async () => { + ensureProject(); + + const myapp1 = uniq('myapp1'); + const myapp2 = uniq('myapp2'); + runCLI(`generate @nrwl/web:app ${myapp1}`); + runCLI(`generate @nrwl/web:app ${myapp2}`); + const files = `--files="apps/${myapp1}/src/main.ts,apps/${myapp2}/src/main.ts"`; + + // run without caching + // -------------------------------------------- + const outputWithoutCachingEnabled1 = runCommand( + `npm run affected:build -- ${files}` + ); + const filesApp1 = listFiles(`dist/apps/${myapp1}`); + const filesApp2 = listFiles(`dist/apps/${myapp2}`); + + expect(outputWithoutCachingEnabled1).not.toContain( + 'read the output from cache' + ); + + const outputWithoutCachingEnabled2 = runCommand( + `npm run affected:build -- ${files}` + ); + expect(outputWithoutCachingEnabled2).not.toContain( + 'read the output from cache' + ); + + // enable caching + // -------------------------------------------- + updateFile('nx.json', c => { + const nxJson = JSON.parse(c); + nxJson.tasksRunnerOptions = { + default: { + runner: '@nrwl/workspace/src/tasks-runner/tasks-runner-v2', + options: { + cacheableOperations: ['build', 'lint'] + } + } + }; + return JSON.stringify(nxJson, null, 2); + }); + + // run build with caching + // -------------------------------------------- + const outputThatPutsDataIntoCache = runCommand( + `npm run affected:build -- ${files}` + ); + // now the data is in cache + expect(outputThatPutsDataIntoCache).not.toContain( + 'read the output from cache' + ); + + rmDist(); + + const outputWithBothBuildTasksCached = runCommand( + `npm run affected:build -- ${files}` + ); + expect(outputWithBothBuildTasksCached).toContain( + 'read the output from cache' + ); + expectCached(outputWithBothBuildTasksCached, [myapp1, myapp2]); + expect(listFiles(`dist/apps/${myapp1}`)).toEqual(filesApp1); + expect(listFiles(`dist/apps/${myapp2}`)).toEqual(filesApp2); + + // touch myapp1 + // -------------------------------------------- + updateFile(`apps/${myapp1}/src/main.ts`, c => { + return `${c}\n//some comment`; + }); + const outputWithBuildApp2Cached = runCommand( + `npm run affected:build -- ${files}` + ); + expect(outputWithBuildApp2Cached).toContain( + 'read the output from cache' + ); + expectCached(outputWithBuildApp2Cached, [myapp2]); + + // touch package.json + // -------------------------------------------- + updateFile(`package.json`, c => { + const r = JSON.parse(c); + r.description = 'different'; + return JSON.stringify(r); + }); + const outputWithNoBuildCached = runCommand( + `npm run affected:build -- ${files}` + ); + expect(outputWithNoBuildCached).not.toContain( + 'read the output from cache' + ); + + // run lint with caching + // -------------------------------------------- + const outputWithNoLintCached = runCommand( + `npm run affected:lint -- ${files}` + ); + expect(outputWithNoLintCached).not.toContain( + 'read the output from cache' + ); + + const outputWithBothLintTasksCached = runCommand( + `npm run affected:lint -- ${files}` + ); + expect(outputWithBothLintTasksCached).toContain( + 'read the output from cache' + ); + expectCached(outputWithBothLintTasksCached, [ + myapp1, + myapp2, + `${myapp1}-e2e`, + `${myapp2}-e2e` + ]); + }, 120000); + }); + }); + + function expectCached(actual: string, expected: string[]) { + const section = actual.split('read the output from cache')[1]; + const r = section + .split('\n') + .filter(l => l.trim().startsWith('-')) + .map(l => l.split('- ')[1].trim()); + r.sort((a, b) => a.localeCompare(b)); + expected.sort((a, b) => a.localeCompare(b)); + expect(r).toEqual(expected); + } +}); diff --git a/package.json b/package.json index 00aacdb198..40f4c7afd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nrwl/nx-source", - "version": "8.9.0", + "version": "8.10.0-beta.7", "description": "Extensible Dev Tools for Monorepos", "homepage": "https://nx.dev", "main": "index.js", diff --git a/packages/workspace/src/tasks-runner/run-command.ts b/packages/workspace/src/tasks-runner/run-command.ts index d9e6c69fa6..99fc5b2fc8 100644 --- a/packages/workspace/src/tasks-runner/run-command.ts +++ b/packages/workspace/src/tasks-runner/run-command.ts @@ -29,11 +29,10 @@ export function runCommand( }) ); - const { tasksRunner, tasksOptions } = getRunner( - nxArgs.runner, - nxJson, - overrides - ); + const { tasksRunner, tasksOptions } = getRunner(nxArgs.runner, nxJson, { + ...nxArgs, + ...overrides + }); const cached = []; tasksRunner(tasks, tasksOptions, { target: nxArgs.target, diff --git a/scripts/e2e-ci2.sh b/scripts/e2e-ci2.sh index e314a142a7..d303bdbf77 100755 --- a/scripts/e2e-ci2.sh +++ b/scripts/e2e-ci2.sh @@ -19,4 +19,4 @@ jest --maxWorkers=1 ./build/e2e/run-many.test.js && jest --maxWorkers=1 ./build/e2e/storybook.test.js && jest --maxWorkers=1 ./build/e2e/upgrade-module.test.js && jest --maxWorkers=1 ./build/e2e/web.test.js && -jest --maxWorkers=1 ./build/e2e/cache.test.js +jest --maxWorkers=1 ./build/e2e/default-tasks-runner.test.js