diff --git a/e2e/gatsby/src/gatsby.test.ts b/e2e/gatsby/src/gatsby.test.ts index 6a1aa9d5a6..0e6368e63a 100644 --- a/e2e/gatsby/src/gatsby.test.ts +++ b/e2e/gatsby/src/gatsby.test.ts @@ -41,7 +41,7 @@ describe('Gatsby Applications', () => { expect(testResults.combinedOutput).toContain( 'Test Suites: 2 passed, 2 total' ); - }, 120000); + }, 300000); test('supports --js option', async () => { const app = uniq('app'); @@ -55,5 +55,5 @@ describe('Gatsby Applications', () => { const result = runCLI(`build ${app}`); expect(result).toContain('Done building in'); - }, 120000); + }, 300000); }); diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index 0837323a85..1b0d735929 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -8,8 +8,9 @@ import { } from '@nrwl/e2e/utils'; describe('Jest', () => { - it('should be able test projects using jest', async (done) => { - newProject(); + beforeEach(() => newProject()); + + it('should be able test projects using jest', async () => { const mylib = uniq('mylib'); const myapp = uniq('myapp'); runCLI(`generate @nrwl/angular:app ${myapp} --unit-test-runner jest`); @@ -31,11 +32,9 @@ describe('Jest', () => { expect(libResult.combinedOutput).toContain( 'Test Suites: 3 passed, 3 total' ); - done(); - }, 45000); + }, 500000); - it('should merge with jest config globals', async (done) => { - newProject(); + it('should merge with jest config globals', async () => { const testGlobal = `'My Test Global'`; const mylib = uniq('mylib'); runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); @@ -71,11 +70,9 @@ describe('Jest', () => { expect(appResult.combinedOutput).toContain( 'Test Suites: 1 passed, 1 total' ); - done(); - }, 45000); + }, 90000); - it('should set the NODE_ENV to `test`', async (done) => { - newProject(); + it('should set the NODE_ENV to `test`', async () => { const mylib = uniq('mylib'); runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); @@ -91,11 +88,9 @@ describe('Jest', () => { expect(appResult.combinedOutput).toContain( 'Test Suites: 1 passed, 1 total' ); - done(); - }, 45000); + }, 90000); - it('should support multiple `coverageReporters` through CLI', async (done) => { - newProject(); + it('should support multiple `coverageReporters` through CLI', async () => { const mylib = uniq('mylib'); runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); @@ -115,6 +110,5 @@ describe('Jest', () => { 'File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s' ); // text expect(result.stdout).toContain('Coverage summary'); // text-summary - done(); - }, 45000); + }, 90000); }); diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index 4c6671c26f..ed781ed2b0 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -35,8 +35,9 @@ function getData(): Promise { } describe('Node Applications', () => { + beforeEach(() => newProject()); + it('should be able to generate an empty application', async () => { - newProject(); const nodeapp = uniq('nodeapp'); runCLI(`generate @nrwl/node:app ${nodeapp} --linter=eslint`); @@ -54,8 +55,7 @@ describe('Node Applications', () => { expect(result).toContain('Hello World!'); }, 60000); - it('should be able to generate an express application', async (done) => { - newProject(); + it('should be able to generate an express application', async () => { const nodeapp = uniq('nodeapp'); runCLI(`generate @nrwl/express:app ${nodeapp} --linter=eslint`); @@ -111,12 +111,10 @@ describe('Node Applications', () => { expect(result.message).toEqual(`Welcome to ${nodeapp}!`); treeKill(process.pid, 'SIGTERM', (err) => { expect(err).toBeFalsy(); - done(); }); }, 120000); - it('should be able to generate a nest application', async (done) => { - newProject(); + it('should be able to generate a nest application', async () => { const nestapp = uniq('nestapp'); runCLI(`generate @nrwl/nest:app ${nestapp} --linter=eslint`); @@ -166,11 +164,13 @@ describe('Node Applications', () => { expect(result.message).toEqual(`Welcome to ${nestapp}!`); treeKill(process.pid, 'SIGTERM', (err) => { expect(err).toBeFalsy(); - done(); }); }, 120000); }); + describe('Build Node apps', () => { + beforeEach(() => newProject()); + it('should generate a package.json with the `--generatePackageJson` flag', async () => { newProject(); const nestapp = uniq('nestapp'); @@ -196,7 +196,7 @@ describe('Build Node apps', () => { version: '0.0.1', }) ); - }); + }, 300000); }); describe('Node Libraries', () => { @@ -215,7 +215,7 @@ describe('Node Libraries', () => { ); checkFilesDoNotExist(`libs/${nodelib}/package.json`); - }, 60000); + }, 300000); it('should be able to generate a publishable node library', async () => { const proj = newProject(); @@ -266,7 +266,7 @@ describe('Node Libraries', () => { main: './src/index.js', typings: './src/index.d.ts', }); - }, 60000); + }, 300000); it('should be able to generate a publishable node library with CLI wrapper', async () => { const proj = newProject(); @@ -298,7 +298,7 @@ describe('Node Libraries', () => { createFile(`dist/libs/${nodeLib}/_should_keep.txt`); await runCLIAsync(`build ${nodeLib} --delete-output-path=false`); checkFilesExist(`dist/libs/${nodeLib}/_should_keep.txt`); - }, 60000); + }, 300000); it('should support --js flag', async () => { const proj = newProject(); @@ -323,7 +323,7 @@ describe('Node Libraries', () => { `dist/libs/${nodeLib}/src/index.js`, `dist/libs/${nodeLib}/package.json` ); - }, 60000); + }, 300000); it('should be able to copy assets', () => { const proj = newProject(); @@ -354,7 +354,7 @@ describe('Node Libraries', () => { runCLI(`build ${nglib}`); runCLI(`build ${nodelib}`); checkFilesExist(`./dist/libs/${nodelib}/esm2015/index.js`); - }, 120000); + }, 300000); it('should fail when trying to compile typescript files that are invalid', () => { const proj = newProject(); @@ -373,10 +373,10 @@ describe('Node Libraries', () => { }); describe('nest libraries', function () { - it('should be able to generate a nest library', async () => { - newProject(); - const nestlib = uniq('nestlib'); + beforeEach(() => newProject()); + it('should be able to generate a nest library', async () => { + const nestlib = uniq('nestlib'); runCLI(`generate @nrwl/nest:lib ${nestlib}`); const jestConfigContent = readFile(`libs/${nestlib}/jest.config.js`); @@ -405,7 +405,6 @@ describe('nest libraries', function () { }, 60000); it('should be able to generate a nest library w/ service', async () => { - newProject(); const nestlib = uniq('nestlib'); runCLI(`generate @nrwl/nest:lib ${nestlib} --service`); @@ -417,10 +416,9 @@ describe('nest libraries', function () { expect(jestResult.combinedOutput).toContain( 'Test Suites: 1 passed, 1 total' ); - }, 60000); + }, 200000); it('should be able to generate a nest library w/ controller', async () => { - newProject(); const nestlib = uniq('nestlib'); runCLI(`generate @nrwl/nest:lib ${nestlib} --controller`); @@ -432,10 +430,9 @@ describe('nest libraries', function () { expect(jestResult.combinedOutput).toContain( 'Test Suites: 1 passed, 1 total' ); - }, 60000); + }, 200000); it('should be able to generate a nest library w/ controller and service', async () => { - newProject(); const nestlib = uniq('nestlib'); runCLI(`generate @nrwl/nest:lib ${nestlib} --controller --service`); @@ -447,7 +444,7 @@ describe('nest libraries', function () { expect(jestResult.combinedOutput).toContain( 'Test Suites: 2 passed, 2 total' ); - }, 60000); + }, 200000); }); describe('with dependencies', () => { diff --git a/e2e/nx-plugin/src/nx-plugin.test.ts b/e2e/nx-plugin/src/nx-plugin.test.ts index 5736466b53..c9c2eddef9 100644 --- a/e2e/nx-plugin/src/nx-plugin.test.ts +++ b/e2e/nx-plugin/src/nx-plugin.test.ts @@ -11,8 +11,9 @@ import { } from '@nrwl/e2e/utils'; describe('Nx Plugin', () => { - it('should be able to generate a Nx Plugin ', async (done) => { - newProject(); + beforeEach(() => newProject()); + + it('should be able to generate a Nx Plugin ', async () => { const plugin = uniq('plugin'); runCLI( @@ -50,15 +51,13 @@ describe('Nx Plugin', () => { }, }), }); - done(); - }, 45000); + }, 90000); // the test invoke ensureNxProject, which points to @nrwl/workspace collection // which walks up the directory to find it in the next repo itself, so it // doesn't use the collection we are building // we should change it to point to the right collection using relative path - it(`should run the plugin's e2e tests`, async (done) => { - newProject(); + it(`should run the plugin's e2e tests`, async () => { const plugin = uniq('plugin-name'); runCLI( `generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --importPath=@proj/${plugin}` @@ -69,12 +68,9 @@ describe('Nx Plugin', () => { expect(results.stdout).toContain('Compiling TypeScript files'); expectTestsPass(results); } - - done(); }, 250000); - it('should be able to generate a migration', async (done) => { - newProject(); + it('should be able to generate a migration', async () => { const plugin = uniq('plugin'); const version = '1.0.0'; @@ -108,11 +104,9 @@ describe('Nx Plugin', () => { }, }), }); - done(); - }, 45000); + }, 90000); - it('should be able to generate a generator', async (done) => { - newProject(); + it('should be able to generate a generator', async () => { const plugin = uniq('plugin'); const generator = uniq('generator'); @@ -150,11 +144,9 @@ describe('Nx Plugin', () => { }, }), }); - done(); - }, 45000); + }, 90000); - it('should be able to generate a executor', async (done) => { - newProject(); + it('should be able to generate a executor', async () => { const plugin = uniq('plugin'); const executor = uniq('executor'); @@ -190,12 +182,10 @@ describe('Nx Plugin', () => { }, }), }); - done(); - }, 45000); + }, 90000); describe('--directory', () => { it('should create a plugin in the specified directory', () => { - newProject(); const plugin = uniq('plugin'); runCLI( `generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --directory subdir --importPath=@proj/${plugin}` @@ -207,17 +197,16 @@ describe('Nx Plugin', () => { `libs/subdir/${plugin}` ); expect(workspace.projects[`subdir-${plugin}-e2e`]).toBeTruthy(); - }, 45000); + }, 90000); }); describe('--tags', () => { it('should add tags to nx.json', async () => { - newProject(); const plugin = uniq('plugin'); runCLI( `generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage --importPath=@proj/${plugin}` ); const nxJson = readJson('nx.json'); expect(nxJson.projects[plugin].tags).toEqual(['e2etag', 'e2ePackage']); - }, 45000); + }, 90000); }); }); diff --git a/e2e/react/src/react.test.ts b/e2e/react/src/react.test.ts index 8a7671e2da..fb863f9bed 100644 --- a/e2e/react/src/react.test.ts +++ b/e2e/react/src/react.test.ts @@ -15,8 +15,11 @@ import { } from '@nrwl/e2e/utils'; describe('React Applications', () => { + let proj: string; + + beforeEach(() => (proj = newProject())); + it('should be able to generate a react app + lib', async () => { - const proj = newProject(); const appName = uniq('app'); const libName = uniq('lib'); @@ -43,10 +46,9 @@ describe('React Applications', () => { checkLinter: true, checkE2E: true, }); - }, 120000); + }, 500000); it('should support vendor sourcemaps', () => { - newProject(); const appName = uniq('app'); runCLI(`generate @nrwl/react:app ${appName} --no-interactive`); @@ -66,10 +68,9 @@ describe('React Applications', () => { runCLI(`build ${appName}`); checkFilesExist(`dist/apps/${appName}/vendor.js.map`); - }, 120000); + }, 250000); it('should be able to generate a publishable react lib', async () => { - const proj = newProject(); const libName = uniq('lib'); runCLI( @@ -103,10 +104,9 @@ describe('React Applications', () => { `dist/libs/${libName}/${libName}.umd.css`, `dist/libs/${libName}/${libName}.umd.js` ); - }, 120000); + }, 250000); it('should be able to generate a react lib with no components', async () => { - const proj = newProject(); const appName = uniq('app'); const libName = uniq('lib'); @@ -130,10 +130,9 @@ describe('React Applications', () => { checkLinter: false, checkE2E: false, }); - }, 120000); + }, 250000); it('should not create a dist folder if there is an error', async () => { - const proj = newProject(); const libName = uniq('lib'); runCLI( @@ -149,10 +148,9 @@ describe('React Applications', () => { expect(() => { checkFilesExist(`dist/libs/${libName}/package.json`); }).toThrow(); - }, 120000); + }, 250000); it('should generate app with routing', async () => { - newProject(); const appName = uniq('app'); runCLI(`generate @nrwl/react:app ${appName} --routing --no-interactive`); @@ -163,11 +161,9 @@ describe('React Applications', () => { checkLinter: false, checkE2E: false, }); - }, 120000); + }, 250000); it('should generate app with different style options', async () => { - newProject(); - const styledComponentsApp = uniq('app'); runCLI( @@ -245,10 +241,9 @@ describe('React Applications', () => { expect(readFile(`dist/apps/${noStylesApp}/index.html`)).not.toContain( `` ); - }, 120000); + }, 250000); it('should generate app with legacy-ie support', async () => { - newProject(); const appName = uniq('app'); runCLI(`generate @nrwl/react:app ${appName} --style=css --no-interactive`); @@ -273,10 +268,9 @@ describe('React Applications', () => { expect(readFile(`dist/apps/${appName}/prod/index.html`)).toContain( `` ); - }, 120000); + }, 250000); it('should be able to add a redux slice', async () => { - newProject(); const appName = uniq('app'); const libName = uniq('lib'); @@ -294,10 +288,9 @@ describe('React Applications', () => { expect(libTestResults.combinedOutput).toContain( 'Test Suites: 2 passed, 2 total' ); - }, 120000); + }, 250000); it('should be able to use JSX', async () => { - const proj = newProject(); const appName = uniq('app'); const libName = uniq('lib'); @@ -339,7 +332,7 @@ describe('React Applications', () => { checkLinter: false, checkE2E: false, }); - }, 30000); + }, 250000); async function testGeneratedApp( appName, diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index 7bb8b1dfcb..08dc4b01b7 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -184,7 +184,9 @@ export function removeProject({ onlyOnCI = false } = {}) { if (onlyOnCI && !isCI) { return; } - removeSync(tmpProjPath()); + try { + removeSync(tmpProjPath()); + } catch (e) {} } export function runCypressTests() { diff --git a/e2e/web/src/file-server.test.ts b/e2e/web/src/file-server.test.ts index 2cddc5a441..2162cdf965 100644 --- a/e2e/web/src/file-server.test.ts +++ b/e2e/web/src/file-server.test.ts @@ -10,8 +10,9 @@ import { import { serializeJson } from '@nrwl/workspace'; describe('file-server', () => { - it('should serve folder of files', async (done) => { - newProject(); + beforeEach(() => newProject()); + + it('should serve folder of files', async () => { const appName = uniq('app'); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); @@ -25,8 +26,5 @@ describe('file-server', () => { output.indexOf('Built at') > -1 && output.indexOf('Available on') > -1 ); }); - - // success, nothing to do - done(); - }, 30000); + }, 300000); }); diff --git a/e2e/web/src/web.test.ts b/e2e/web/src/web.test.ts index bc1793316e..93159c509a 100644 --- a/e2e/web/src/web.test.ts +++ b/e2e/web/src/web.test.ts @@ -13,8 +13,8 @@ import { } from '@nrwl/e2e/utils'; describe('Web Components Applications', () => { + beforeEach(() => newProject()); it('should be able to generate a web app', async () => { - newProject(); const appName = uniq('app'); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); @@ -54,10 +54,9 @@ describe('Web Components Applications', () => { const e2eResults = runCLI(`e2e ${appName}-e2e`); expect(e2eResults).toContain('All specs passed!'); } - }, 120000); + }, 500000); it('should remove previous output before building', async () => { - newProject(); const appName = uniq('app'); const libName = uniq('lib'); @@ -90,7 +89,6 @@ describe('Web Components Applications', () => { }, 120000); it('should do another build if differential loading is needed', async () => { - newProject(); const appName = uniq('app'); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); @@ -110,7 +108,6 @@ describe('Web Components Applications', () => { }, 120000); it('should emit decorator metadata when it is enabled in tsconfig', async () => { - newProject(); const appName = uniq('app'); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); diff --git a/e2e/workspace/src/run-commands.test.ts b/e2e/workspace/src/run-commands.test.ts index 01e74aa717..62a403dc8f 100644 --- a/e2e/workspace/src/run-commands.test.ts +++ b/e2e/workspace/src/run-commands.test.ts @@ -13,7 +13,7 @@ describe('Run Commands', () => { afterAll(() => removeProject({ onlyOnCI: true })); - it('should not override environment variables already set when setting a custom env file path', async (done) => { + it('should not override environment variables already set when setting a custom env file path', async () => { const nodeapp = uniq('nodeapp'); updateFile( `.env`, @@ -45,10 +45,9 @@ describe('Run Commands', () => { expect(result).not.toContain('shared-nested-value'); expect(result).toContain('root-only-value'); expect(result).toContain('nested-only-value'); - done(); }, 120000); - it('should pass options', async (done) => { + it('should pass options', async () => { const myapp = uniq('myapp1'); runCLI(`generate @nrwl/web:app ${myapp}`); @@ -70,10 +69,9 @@ describe('Run Commands', () => { expect(result).toContain( '--var1=a --var2=b --var-hyphen=c --varCamelCase=d' ); - done(); }, 120000); - it('should interpolate provided arguments', async (done) => { + it('should interpolate provided arguments', async () => { const myapp = uniq('myapp1'); runCLI(`generate @nrwl/web:app ${myapp}`); @@ -107,7 +105,6 @@ describe('Run Commands', () => { expect(resultArgs).toContain('var2: b'); expect(resultArgs).toContain('hyphen: c'); expect(resultArgs).toContain('camel: d'); - done(); }, 120000); it('should fail when a process exits non-zero', () => { diff --git a/e2e/workspace/src/workspace-aux-commands.test.ts b/e2e/workspace/src/workspace-aux-commands.test.ts index c693f33035..67e5a09773 100644 --- a/e2e/workspace/src/workspace-aux-commands.test.ts +++ b/e2e/workspace/src/workspace-aux-commands.test.ts @@ -238,7 +238,7 @@ describe('format', () => { expect(runCLI('format:check --all')).not.toContain( path.normalize(`apps/${myapp}/src/main.ts`) ); - }); + }, 90000); }); describe('workspace-generator', () => { @@ -449,7 +449,7 @@ describe('dep-graph', () => { const jsonFileContents = readJson('project-graph.json'); expect(jsonFileContents.graph.dependencies).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ [myapp3E2e]: [ { source: myapp3E2e, diff --git a/jest.preset.js b/jest.preset.js index 699ad8e545..b41e69db8e 100644 --- a/jest.preset.js +++ b/jest.preset.js @@ -4,6 +4,7 @@ process.env.npm_config_registry = `http://localhost:4872`; module.exports = { ...nxPreset, + testRunner: 'jest-circus/runner', testTimeout: 30000, testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], transform: { diff --git a/package.json b/package.json index e0f5b6fbc7..76f1fa1e06 100644 --- a/package.json +++ b/package.json @@ -157,6 +157,7 @@ "jasmine-marbles": "~0.6.0", "jasmine-spec-reporter": "~4.2.1", "jest": "26.6.3", + "jest-circus": "^26.6.3", "jest-preset-angular": "8.4.0", "karma": "~4.0.0", "karma-chrome-launcher": "~2.2.0", diff --git a/packages/angular/src/builders/package/package.impl.spec.ts b/packages/angular/src/builders/package/package.impl.spec.ts index aab60698bd..0d4a23f73e 100644 --- a/packages/angular/src/builders/package/package.impl.spec.ts +++ b/packages/angular/src/builders/package/package.impl.spec.ts @@ -152,7 +152,7 @@ describe('empty', () => { // // assert // expect(result.success).toBeTruthy(); // expect(ngPackagrMock.withTsConfig).toHaveBeenCalledWith( -// jasmine.objectContaining({ +// expect.objectContaining({ // options: { // paths: { '@proj/buildable-child': ['dist/libs/buildable-child'] }, // }, @@ -184,7 +184,7 @@ describe('empty', () => { // expect(result.success).toBeTruthy(); // expect(fileUtils.writeJsonFile).toHaveBeenCalledWith( // 'dist/libs/buildable-parent/package.json', -// jasmine.objectContaining({ +// expect.objectContaining({ // dependencies: { // '@proj/buildable-child': '1.2.3', // }, diff --git a/packages/angular/src/schematics/application/application.spec.ts b/packages/angular/src/schematics/application/application.spec.ts index ddcb21eb00..0702d36e97 100644 --- a/packages/angular/src/schematics/application/application.spec.ts +++ b/packages/angular/src/schematics/application/application.spec.ts @@ -323,7 +323,7 @@ describe('app', () => { describe('--skipFormat', () => { it('should format files by default', async () => { - const spy = spyOn(prettier, 'getFileInfo').and.callThrough(); + const spy = jest.spyOn(prettier, 'getFileInfo'); appTree = await runSchematic('app', { name: 'myApp' }, appTree); @@ -331,7 +331,7 @@ describe('app', () => { }); it('should skip format when set to true', async () => { - const spy = spyOn(prettier, 'format').and.callThrough(); + const spy = jest.spyOn(prettier, 'format'); appTree = await runSchematic( 'app', diff --git a/packages/cypress/src/executors/cypress/cypress.impl.spec.ts b/packages/cypress/src/executors/cypress/cypress.impl.spec.ts index 66ff8cdada..fb5a3036b5 100644 --- a/packages/cypress/src/executors/cypress/cypress.impl.spec.ts +++ b/packages/cypress/src/executors/cypress/cypress.impl.spec.ts @@ -10,8 +10,8 @@ import { installedCypressVersion } from '../../utils/cypress-version'; const Cypress = require('cypress'); describe('Cypress builder', () => { - let cypressRun: jasmine.Spy; - let cypressOpen: jasmine.Spy; + let cypressRun: jest.SpyInstance; + let cypressOpen: jest.SpyInstance; const cypressOptions: CypressExecutorOptions = { cypressConfig: 'apps/my-app-e2e/cypress.json', parallel: false, @@ -47,25 +47,30 @@ describe('Cypress builder', () => { configuration, }; }; - cypressRun = spyOn(Cypress, 'run').and.returnValue(Promise.resolve({})); - cypressOpen = spyOn(Cypress, 'open').and.returnValue(Promise.resolve({})); + cypressRun = jest + .spyOn(Cypress, 'run') + .mockReturnValue(Promise.resolve({})); + cypressOpen = jest + .spyOn(Cypress, 'open') + .mockReturnValue(Promise.resolve({})); }); - it('should call `Cypress.run` if headless mode is `true`', async (done) => { + afterEach(() => jest.clearAllMocks()); + + it('should call `Cypress.run` if headless mode is `true`', async () => { const { success } = await cypressExecutor(cypressOptions, mockContext); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ config: { baseUrl: 'http://localhost:4200' }, project: path.dirname(cypressOptions.cypressConfig), }) ); expect(cypressOpen).not.toHaveBeenCalled(); - done(); }); - it('should call `Cypress.open` if headless mode is `false`', async (done) => { + it('should call `Cypress.open` if headless mode is `false`', async () => { const { success } = await cypressExecutor( { ...cypressOptions, headless: false, watch: true }, mockContext @@ -73,16 +78,15 @@ describe('Cypress builder', () => { expect(success).toEqual(true); expect(cypressOpen).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ config: { baseUrl: 'http://localhost:4200' }, project: path.dirname(cypressOptions.cypressConfig), }) ); expect(cypressRun).not.toHaveBeenCalled(); - done(); }); - it('should fail early if application build fails', async (done) => { + it('should fail early if application build fails', async () => { (devkit as any).runExecutor = jest.fn().mockReturnValue([ { success: false, @@ -92,10 +96,9 @@ describe('Cypress builder', () => { await cypressExecutor(cypressOptions, mockContext); fail('Should not execute'); } catch (e) {} - done(); }); - it('should show warnings if using unsupported browsers v3', async (done) => { + it('should show warnings if using unsupported browsers v3', async () => { mockedInstalledCypressVersion.mockReturnValue(3); await cypressExecutor( { @@ -106,10 +109,9 @@ describe('Cypress builder', () => { ); expect(devkit.logger.warn).toHaveBeenCalled(); - done(); }); - it('should show warnings if using unsupported browsers v4', async (done) => { + it('should show warnings if using unsupported browsers v4', async () => { mockedInstalledCypressVersion.mockReturnValue(4); await cypressExecutor( { @@ -120,10 +122,9 @@ describe('Cypress builder', () => { ); expect(devkit.logger.warn).toHaveBeenCalled(); - done(); }); - it('should call `Cypress.run` with provided baseUrl', async (done) => { + it('should call `Cypress.run` with provided baseUrl', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -134,17 +135,16 @@ describe('Cypress builder', () => { ); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ config: { baseUrl: 'http://my-distant-host.com', }, project: path.dirname(cypressOptions.cypressConfig), }) ); - done(); }); - it('should call `Cypress.run` with provided browser', async (done) => { + it('should call `Cypress.run` with provided browser', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -154,15 +154,14 @@ describe('Cypress builder', () => { ); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ browser: 'chrome', project: path.dirname(cypressOptions.cypressConfig), }) ); - done(); }); - it('should call `Cypress.run` without baseUrl nor dev server target value', async (done) => { + it('should call `Cypress.run` without baseUrl nor dev server target value', async () => { const { success } = await cypressExecutor( { cypressConfig: 'apps/my-app-e2e/cypress.json', @@ -180,14 +179,13 @@ describe('Cypress builder', () => { ); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ project: path.dirname(cypressOptions.cypressConfig), }) ); - done(); }); - it('should call `Cypress.run` with a string of files to ignore', async (done) => { + it('should call `Cypress.run` with a string of files to ignore', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -197,14 +195,13 @@ describe('Cypress builder', () => { ); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ ignoreTestFiles: '/some/path/to/a/file.js', }) ); - done(); }); - it('should call `Cypress.run` with a reporter and reporterOptions', async (done) => { + it('should call `Cypress.run` with a reporter and reporterOptions', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -215,15 +212,14 @@ describe('Cypress builder', () => { ); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ reporter: 'junit', reporterOptions: 'mochaFile=reports/results-[hash].xml,toConsole=true', }) ); - done(); }); - it('should call `Cypress.run` with provided cypressConfig as project and configFile', async (done) => { + it('should call `Cypress.run` with provided cypressConfig as project and configFile', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -233,15 +229,14 @@ describe('Cypress builder', () => { ); expect(success).toEqual(true); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ project: 'some/project', configFile: 'my-cypress.json', }) ); - done(); }); - it('when devServerTarget AND baseUrl options are both present, baseUrl should take precedence', async (done) => { + it('when devServerTarget AND baseUrl options are both present, baseUrl should take precedence', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -250,22 +245,28 @@ describe('Cypress builder', () => { mockContext ); expect(success).toEqual(true); - expect(cypressRun.calls.mostRecent().args[0].config.baseUrl).toBe( - 'test-url-from-options' + expect(cypressRun).toHaveBeenLastCalledWith( + expect.objectContaining({ + config: { + baseUrl: 'test-url-from-options', + }, + }) ); - done(); }); - it('when devServerTarget option present and baseUrl option is absent, baseUrl should come from devServerTarget', async (done) => { + it('when devServerTarget option present and baseUrl option is absent, baseUrl should come from devServerTarget', async () => { const { success } = await cypressExecutor(cypressOptions, mockContext); expect(success).toEqual(true); - expect(cypressRun.calls.mostRecent().args[0].config.baseUrl).toBe( - 'http://localhost:4200' + expect(cypressRun).toHaveBeenLastCalledWith( + expect.objectContaining({ + config: { + baseUrl: 'http://localhost:4200', + }, + }) ); - done(); }); - it('should call `Cypress.run` without serving the app', async (done) => { + it('should call `Cypress.run` without serving the app', async () => { const { success } = await cypressExecutor( { ...cypressOptions, @@ -277,12 +278,11 @@ describe('Cypress builder', () => { expect(success).toEqual(true); expect(runExecutor).not.toHaveBeenCalled(); expect(cypressRun).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ config: { baseUrl: 'http://my-distant-host.com', }, }) ); - done(); }); }); diff --git a/packages/jest/src/executors/jest/jest.impl.spec.ts b/packages/jest/src/executors/jest/jest.impl.spec.ts index ebba4f8d41..7694baac33 100644 --- a/packages/jest/src/executors/jest/jest.impl.spec.ts +++ b/packages/jest/src/executors/jest/jest.impl.spec.ts @@ -74,7 +74,7 @@ describe('Jest Executor', () => { mockContext ); expect(runCLI).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ _: [], testPathPattern: [], watch: false, @@ -103,7 +103,7 @@ describe('Jest Executor', () => { ); expect(runCLI).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ _: ['lib.spec.ts'], coverage: false, runInBand: true, @@ -135,7 +135,7 @@ describe('Jest Executor', () => { ); expect(runCLI).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ _: ['file1.ts', 'file2.ts'], coverage: false, findRelatedTests: true, @@ -243,7 +243,7 @@ describe('Jest Executor', () => { mockContext ); expect(runCLI).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ _: [], setupFilesAfterEnv: ['/root/test-setup.ts'], testPathPattern: [], @@ -279,7 +279,7 @@ describe('Jest Executor', () => { ); expect(runCLI).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ _: [], setupFilesAfterEnv: ['/root/test-setup.ts'], testPathPattern: [], @@ -312,7 +312,7 @@ describe('Jest Executor', () => { await jestExecutor(options, mockContext); expect(runCLI).toHaveBeenCalledWith( - jasmine.objectContaining({ + expect.objectContaining({ _: [], testPathPattern: [], watch: false, diff --git a/packages/jest/src/migrations/update-10-0-0/update-jest-configs.spec.ts b/packages/jest/src/migrations/update-10-0-0/update-jest-configs.spec.ts index 0b1e43175b..0cd5a495ce 100644 --- a/packages/jest/src/migrations/update-10-0-0/update-jest-configs.spec.ts +++ b/packages/jest/src/migrations/update-10-0-0/update-jest-configs.spec.ts @@ -111,7 +111,7 @@ describe('update 10.0.0', () => { ); }); - it('should remove setupFile and tsconfig in test architect from workspace.json', async (done) => { + it('should remove setupFile and tsconfig in test architect from workspace.json', async () => { const result = await schematicRunner .runSchematicAsync('update-10.0.0', {}, initialTree) .toPromise(); @@ -125,10 +125,9 @@ describe('update 10.0.0', () => { jestConfig: expect.anything(), passWithNoTests: expect.anything(), }); - done(); }); - it('should update the jest.config files', async (done) => { + it('should update the jest.config files', async () => { await schematicRunner .runSchematicAsync('update-10.0.0', {}, initialTree) .toPromise(); @@ -163,7 +162,5 @@ describe('update 10.0.0', () => { const reactGlobals = reactJestObject.globals; expect(reactSetupFiles).toBeUndefined(); expect(reactGlobals).toBeUndefined(); - - done(); }); }); diff --git a/packages/jest/src/migrations/update-10-2-0/update-10-2-0.spec.ts b/packages/jest/src/migrations/update-10-2-0/update-10-2-0.spec.ts index d07d9d7124..75b2983d1b 100644 --- a/packages/jest/src/migrations/update-10-2-0/update-10-2-0.spec.ts +++ b/packages/jest/src/migrations/update-10-2-0/update-10-2-0.spec.ts @@ -59,7 +59,7 @@ describe('update 10.2.0', () => { ); }); - it('should remove setupFile and tsconfig in test architect from workspace.json', async (done) => { + it('should remove setupFile and tsconfig in test architect from workspace.json', async () => { const result = await schematicRunner .runSchematicAsync('update-10.2.0', {}, initialTree) .toPromise(); @@ -73,6 +73,5 @@ describe('update 10.2.0', () => { jestConfig: expect.anything(), passWithNoTests: expect.anything(), }); - done(); }); }); diff --git a/packages/jest/src/migrations/update-10-3-0/update-projects-property.spec.ts b/packages/jest/src/migrations/update-10-3-0/update-projects-property.spec.ts index b1c58049c7..a11ae39806 100644 --- a/packages/jest/src/migrations/update-10-3-0/update-projects-property.spec.ts +++ b/packages/jest/src/migrations/update-10-3-0/update-projects-property.spec.ts @@ -108,7 +108,7 @@ describe('update projects property', () => { ); }); - it('should remove setupFile and tsconfig in test architect from workspace.json', async (done) => { + it('should remove setupFile and tsconfig in test architect from workspace.json', async () => { const result = await schematicRunner .runSchematicAsync('update-projects-property', {}, initialTree) .toPromise(); @@ -156,7 +156,5 @@ describe('update projects property', () => { displayName: 'products', }; `); - - done(); }); }); diff --git a/packages/jest/src/migrations/update-12-1-0/update-jest-preset-angular.spec.ts b/packages/jest/src/migrations/update-12-1-0/update-jest-preset-angular.spec.ts index 273bea2792..abfd2d48ab 100644 --- a/packages/jest/src/migrations/update-12-1-0/update-jest-preset-angular.spec.ts +++ b/packages/jest/src/migrations/update-12-1-0/update-jest-preset-angular.spec.ts @@ -69,7 +69,7 @@ describe('update 12.1.0', () => { ); }); - it('should update the jest.config files', async (done) => { + it('should update the jest.config files', async () => { await schematicRunner .runSchematicAsync('update-jest-preset-angular-8-4-0', {}, initialTree) .toPromise(); @@ -84,11 +84,9 @@ describe('update 12.1.0', () => { 'jest-preset-angular/build/serializers/ng-snapshot', 'jest-preset-angular/build/serializers/html-comment', ]); - - done(); }); - it('should update the test-setup files', async (done) => { + it('should update the test-setup files', async () => { await schematicRunner .runSchematicAsync('update-jest-preset-angular-8-4-0', {}, initialTree) .toPromise(); @@ -99,7 +97,5 @@ describe('update 12.1.0', () => { .trim(); expect(testSetup).toEqual(`import 'jest-preset-angular/setup-jest';`); - - done(); }); }); diff --git a/packages/jest/src/migrations/utils/config/legacy/update-config.spec.ts b/packages/jest/src/migrations/utils/config/legacy/update-config.spec.ts index 8ebbe9bbe3..2157076c62 100644 --- a/packages/jest/src/migrations/utils/config/legacy/update-config.spec.ts +++ b/packages/jest/src/migrations/utils/config/legacy/update-config.spec.ts @@ -166,7 +166,7 @@ describe('Update jest.config.js', () => { describe('warnings', () => { beforeEach(() => { - spyOn(console, 'warn').and.callThrough(); + jest.spyOn(console, 'warn'); }); it('should warn when trying to add a value to an already existing object without being dot delimited', () => { diff --git a/packages/jest/src/utils/config/update-config.spec.ts b/packages/jest/src/utils/config/update-config.spec.ts index e7fa100cbd..54b56069a5 100644 --- a/packages/jest/src/utils/config/update-config.spec.ts +++ b/packages/jest/src/utils/config/update-config.spec.ts @@ -167,7 +167,7 @@ describe('Update jest.config.js', () => { describe('warnings', () => { beforeEach(() => { - spyOn(console, 'warn').and.callThrough(); + jest.spyOn(console, 'warn'); }); it('should warn when trying to add a value to an already existing object without being dot delimited', () => { diff --git a/packages/node/src/executors/execute/execute.impl.spec.ts b/packages/node/src/executors/execute/execute.impl.spec.ts index d2b9e1a14b..9fbd842c17 100644 --- a/packages/node/src/executors/execute/execute.impl.spec.ts +++ b/packages/node/src/executors/execute/execute.impl.spec.ts @@ -219,11 +219,11 @@ describe('NodeExecuteBuilder', () => { callback(new Error('Error Message')); }); - const loggerError = spyOn(logger, 'error'); + const loggerError = jest.spyOn(logger, 'error'); for await (const event of executeExecutor(testOptions, context)) { } - expect(loggerError.calls.argsFor(0)).toEqual(['Error Message']); + expect(loggerError).toHaveBeenCalledWith('Error Message'); }); it('should log errors from killing the process on windows', async () => { @@ -231,7 +231,7 @@ describe('NodeExecuteBuilder', () => { callback([new Error('error'), '', 'Error Message']); }); - const loggerError = spyOn(logger, 'error'); + const loggerError = jest.spyOn(logger, 'error'); for await (const event of executeExecutor( { @@ -241,7 +241,7 @@ describe('NodeExecuteBuilder', () => { context )) { } - expect(loggerError.calls.argsFor(0)).toEqual(['Error Message']); + expect(loggerError).toHaveBeenLastCalledWith('Error Message'); }); it('should build the application and start the built file with options', async () => { @@ -263,7 +263,7 @@ describe('NodeExecuteBuilder', () => { buildOptions = { optimization: true, }; - const loggerWarn = spyOn(logger, 'warn'); + const loggerWarn = jest.spyOn(logger, 'warn'); for await (const event of executeExecutor( { ...testOptions, diff --git a/packages/node/src/executors/package/package.impl.spec.ts b/packages/node/src/executors/package/package.impl.spec.ts index 8895a075f8..688c7525b6 100644 --- a/packages/node/src/executors/package/package.impl.spec.ts +++ b/packages/node/src/executors/package/package.impl.spec.ts @@ -90,7 +90,7 @@ describe('NodePackageBuilder', () => { describe('Without library dependencies', () => { beforeEach(() => { - spyOn(projectGraph, 'createProjectGraph').and.callFake(() => { + jest.spyOn(projectGraph, 'createProjectGraph').mockImplementation(() => { return { nodes: { nodelib: { @@ -262,7 +262,7 @@ describe('NodePackageBuilder', () => { describe('building with dependencies', () => { beforeEach(() => { // fake that dep project has been built - spyOn(projectGraph, 'createProjectGraph').and.callFake(() => { + jest.spyOn(projectGraph, 'createProjectGraph').mockImplementation(() => { return { nodes: { nodelib: { diff --git a/packages/node/src/utils/config.spec.ts b/packages/node/src/utils/config.spec.ts index ba412b7bbe..610d9cb873 100644 --- a/packages/node/src/utils/config.spec.ts +++ b/packages/node/src/utils/config.spec.ts @@ -80,11 +80,11 @@ describe('getBaseWebpackPartial', () => { }); it('should include module and main in mainFields', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: { target: 'es5', }, - }); + } as any); const result = getBaseWebpackPartial(input); expect(result.resolve.mainFields).toContain('module'); @@ -95,7 +95,7 @@ describe('getBaseWebpackPartial', () => { const result = getBaseWebpackPartial(input); expect(result.stats).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ hash: true, timings: false, cached: false, @@ -151,13 +151,13 @@ describe('getBaseWebpackPartial', () => { }); it('should add the TsConfigPathsPlugin for resolving', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: { paths: { '@npmScope/libraryName': ['libs/libraryName/src/index.ts'], }, }, - }); + } as any); const result = getBaseWebpackPartial(input); expect( result.resolve.plugins.some( @@ -167,11 +167,11 @@ describe('getBaseWebpackPartial', () => { }); it('should include es2015 in mainFields if typescript is set es2015', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: { target: 'es2015', }, - }); + } as any); const result = getBaseWebpackPartial(input); expect(result.resolve.mainFields).toContain('es2015'); @@ -180,9 +180,9 @@ describe('getBaseWebpackPartial', () => { describe('the file replacements option', () => { it('should set aliases', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: {}, - }); + } as any); const result = getBaseWebpackPartial({ ...input, @@ -389,7 +389,7 @@ describe('getBaseWebpackPartial', () => { const result = getBaseWebpackPartial(input); expect(result.stats).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ colors: true, chunks: true, assets: false, @@ -412,7 +412,7 @@ describe('getBaseWebpackPartial', () => { const result = getBaseWebpackPartial(input); expect(result.stats).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ colors: false, chunks: false, assets: true, diff --git a/packages/node/src/utils/normalize.spec.ts b/packages/node/src/utils/normalize.spec.ts index 7cc5e90d63..fcb06b79b2 100644 --- a/packages/node/src/utils/normalize.spec.ts +++ b/packages/node/src/utils/normalize.spec.ts @@ -73,9 +73,9 @@ describe('normalizeBuildOptions', () => { }); it('should normalize asset patterns', () => { - spyOn(fs, 'statSync').and.returnValue({ + jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => true, - }); + } as any); const result = normalizeBuildOptions( { ...testOptions, diff --git a/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts b/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts index 64b8db3f9a..e2277f5068 100644 --- a/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts +++ b/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts @@ -42,7 +42,7 @@ describe('update 10.2.0', () => { ); }); - it('should remove setupFile and tsconfig in test architect from workspace.json', async (done) => { + it('should remove setupFile and tsconfig in test architect from workspace.json', async () => { const result = await schematicRunner .runSchematicAsync('update-10.2.0', {}, initialTree) .toPromise(); @@ -56,6 +56,5 @@ describe('update 10.2.0', () => { pluginOutputPath: expect.anything(), jestConfig: expect.anything(), }); - done(); }); }); diff --git a/packages/react/src/generators/component-story/component-story.spec.ts b/packages/react/src/generators/component-story/component-story.spec.ts index 3ec7f9a169..c8712fdfdf 100644 --- a/packages/react/src/generators/component-story/component-story.spec.ts +++ b/packages/react/src/generators/component-story/component-story.spec.ts @@ -23,7 +23,7 @@ describe('react:component-story', () => { ); }); - it('should fail with a descriptive error message', async (done) => { + it('should fail with a descriptive error message', async () => { try { await componentStoryGenerator(appTree, { componentPath: 'lib/test-ui-lib.tsx', @@ -33,7 +33,6 @@ describe('react:component-story', () => { expect(e.message).toContain( 'Could not find any React component in file libs/test-ui-lib/src/lib/test-ui-lib.tsx' ); - done(); } }); }); diff --git a/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts b/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts index ff0f8c446c..6f68b91dfd 100644 --- a/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts +++ b/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts @@ -39,7 +39,7 @@ describe('Build storybook', () => { }); it('should call the storybook static standalone build', async () => { - spyOn(logger, 'info'); + jest.spyOn(logger, 'info'); const uiFramework = '@storybook/angular'; const outputPath = `${context.root}/dist/storybook`; const config = { diff --git a/packages/web/src/utils/config.spec.ts b/packages/web/src/utils/config.spec.ts index 5ce2196ea3..8be66631cf 100644 --- a/packages/web/src/utils/config.spec.ts +++ b/packages/web/src/utils/config.spec.ts @@ -91,11 +91,11 @@ describe('getBaseWebpackPartial', () => { }); it('should include module and main in mainFields', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: { target: 'es5', }, - }); + } as any); const result = getBaseWebpackPartial(input); expect(result.resolve.mainFields).toContain('module'); @@ -106,7 +106,7 @@ describe('getBaseWebpackPartial', () => { const result = getBaseWebpackPartial(input); expect(result.stats).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ hash: true, timings: false, cached: false, @@ -148,13 +148,13 @@ describe('getBaseWebpackPartial', () => { }); it('should add the TsConfigPathsPlugin for resolving', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: { paths: { '@npmScope/libraryName': ['libs/libraryName/src/index.ts'], }, }, - }); + } as any); const result = getBaseWebpackPartial(input); expect( result.resolve.plugins.some( @@ -171,9 +171,9 @@ describe('getBaseWebpackPartial', () => { describe('the file replacements option', () => { it('should set aliases', () => { - spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ + jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({ options: {}, - }); + } as any); const result = getBaseWebpackPartial({ ...input, @@ -383,7 +383,7 @@ describe('getBaseWebpackPartial', () => { const result = getBaseWebpackPartial(input); expect(result.stats).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ colors: true, chunks: true, assets: false, @@ -406,7 +406,7 @@ describe('getBaseWebpackPartial', () => { const result = getBaseWebpackPartial(input); expect(result.stats).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ colors: false, chunks: false, assets: true, diff --git a/packages/web/src/utils/devserver.config.spec.ts b/packages/web/src/utils/devserver.config.spec.ts index d9e54ddc2a..3fe10ddf30 100644 --- a/packages/web/src/utils/devserver.config.spec.ts +++ b/packages/web/src/utils/devserver.config.spec.ts @@ -67,7 +67,7 @@ describe('getDevServerConfig', () => { target: 'es2015', }; - spyOn(ts, 'readConfigFile').and.callFake(() => ({ + jest.spyOn(ts, 'readConfigFile').mockImplementation(() => ({ config: { compilerOptions: mockCompilerOptions, }, @@ -135,7 +135,7 @@ describe('getDevServerConfig', () => { }, }; - spyOn(logger, 'info'); + jest.spyOn(logger, 'info'); }); it('should print out the URL of the server', () => { @@ -149,7 +149,7 @@ describe('getDevServerConfig', () => { result.onListening(mockServer); expect(logger.info).toHaveBeenCalledWith( - jasmine.stringMatching(new RegExp('http://example.com:9999/')) + expect.stringMatching(new RegExp('http://example.com:9999/')) ); }); @@ -365,7 +365,7 @@ describe('getDevServerConfig', () => { }); it('should configure it with the key and cert provided when on', () => { - spyOn(fs, 'readFileSync').and.callFake((path) => { + jest.spyOn(fs, 'readFileSync').mockImplementation((path: string) => { if (path.endsWith('ssl.key')) { return 'sslKeyContents'; } else if (path.endsWith('ssl.cert')) { diff --git a/packages/web/src/utils/normalize.spec.ts b/packages/web/src/utils/normalize.spec.ts index 46f5328d87..d0f51050f2 100644 --- a/packages/web/src/utils/normalize.spec.ts +++ b/packages/web/src/utils/normalize.spec.ts @@ -47,9 +47,9 @@ describe('normalizeBuildOptions', () => { }); it('should normalize asset patterns', () => { - spyOn(fs, 'statSync').and.returnValue({ + jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => true, - }); + } as any); const result = normalizeBuildOptions( { ...testOptions, diff --git a/packages/web/src/utils/web.config.spec.ts b/packages/web/src/utils/web.config.spec.ts index 4baffa9543..6dd283e088 100644 --- a/packages/web/src/utils/web.config.spec.ts +++ b/packages/web/src/utils/web.config.spec.ts @@ -48,7 +48,7 @@ describe('getWebConfig', () => { TsConfigPathsPlugin )).mockImplementation(function MockPathsPlugin() {}); - spyOn(ts, 'readConfigFile').and.callFake(() => ({ + jest.spyOn(ts, 'readConfigFile').mockImplementation(() => ({ config: { compilerOptions: mockCompilerOptions, }, diff --git a/packages/workspace/src/command-line/workspace-results.spec.ts b/packages/workspace/src/command-line/workspace-results.spec.ts index 457a27227a..898debcea5 100644 --- a/packages/workspace/src/command-line/workspace-results.spec.ts +++ b/packages/workspace/src/command-line/workspace-results.spec.ts @@ -35,9 +35,9 @@ describe('WorkspacesResults', () => { }); it('should remove results from file system', () => { - spyOn(fs, 'writeSync'); - spyOn(fs, 'unlinkSync'); - spyOn(fs, 'existsSync').and.returnValue(true); + jest.spyOn(fs, 'writeSync'); + jest.spyOn(fs, 'unlinkSync').mockImplementationOnce(() => {}); + jest.spyOn(fs, 'existsSync').mockReturnValue(true); results.setResult('proj', true); results.saveResults(); @@ -57,11 +57,11 @@ describe('WorkspacesResults', () => { describe('when results already exist', () => { beforeEach(() => { - spyOn(fs, 'existsSync').and.returnValue(true); + jest.spyOn(fs, 'existsSync').mockReturnValue(true); }); it('should read existing results', () => { - spyOn(fs, 'readFileSync').and.returnValue( + jest.spyOn(fs, 'readFileSync').mockReturnValue( serializeJson({ command: 'test', results: { @@ -84,7 +84,7 @@ describe('WorkspacesResults', () => { }); it('should handle a corrupted results file', () => { - spyOn(fs, 'readFileSync').and.returnValue('invalid json'); + jest.spyOn(fs, 'readFileSync').mockReturnValue('invalid json'); const runTests = () => { results = new WorkspaceResults('test', { @@ -103,7 +103,7 @@ describe('WorkspacesResults', () => { }); it('should not read the existing results when the previous command was different', () => { - spyOn(fs, 'readFileSync').and.returnValue( + jest.spyOn(fs, 'readFileSync').mockReturnValue( serializeJson({ command: 'test', results: { @@ -126,7 +126,7 @@ describe('WorkspacesResults', () => { }); it('should invalidate existing results when the project is not run', () => { - spyOn(fs, 'readFileSync').and.returnValue( + jest.spyOn(fs, 'readFileSync').mockReturnValue( serializeJson({ command: 'test', results: { diff --git a/packages/workspace/src/core/assert-workspace-validity.spec.ts b/packages/workspace/src/core/assert-workspace-validity.spec.ts index 8ac4e08e01..55ab5f9654 100644 --- a/packages/workspace/src/core/assert-workspace-validity.spec.ts +++ b/packages/workspace/src/core/assert-workspace-validity.spec.ts @@ -48,7 +48,7 @@ describe('assertWorkspaceValidity', () => { }); it('should throw for a missing project in workspace.json', () => { - spyOn(output, 'error'); + jest.spyOn(output, 'error'); delete mockWorkspaceJson.projects.app1; const mockExit = jest @@ -67,7 +67,7 @@ describe('assertWorkspaceValidity', () => { }); it('should throw for a missing project in nx.json', () => { - spyOn(output, 'error'); + jest.spyOn(output, 'error'); delete mockNxJson.projects.app1; @@ -87,7 +87,7 @@ describe('assertWorkspaceValidity', () => { }); it('should throw for an invalid top-level implicit dependency', () => { - spyOn(output, 'error'); + jest.spyOn(output, 'error'); mockNxJson.implicitDependencies = { 'README.md': ['invalidproj'], }; @@ -110,7 +110,7 @@ describe('assertWorkspaceValidity', () => { }); it('should throw for an invalid project-level implicit dependency', () => { - spyOn(output, 'error'); + jest.spyOn(output, 'error'); mockNxJson.projects.app2.implicitDependencies = ['invalidproj']; const mockExit = jest @@ -131,7 +131,7 @@ describe('assertWorkspaceValidity', () => { }); it('should throw for a project-level implicit dependency that is a string', () => { - spyOn(output, 'error'); + jest.spyOn(output, 'error'); mockNxJson.implicitDependencies['nx.json'] = 'invalidproj'; const mockExit = jest diff --git a/packages/workspace/src/core/hasher/hasher.spec.ts b/packages/workspace/src/core/hasher/hasher.spec.ts index 80b2245800..9a59f0dd59 100644 --- a/packages/workspace/src/core/hasher/hasher.spec.ts +++ b/packages/workspace/src/core/hasher/hasher.spec.ts @@ -24,7 +24,7 @@ describe('Hasher', () => { }; } - it('should create project hash', async (done) => { + it('should create project hash', async () => { fs.readFileSync = (file) => { if (file === 'workspace.json') { return JSON.stringify({ @@ -93,11 +93,9 @@ describe('Hasher', () => { 'echo runtime123': 'runtime123', 'echo runtime456': 'runtime456', }); - - done(); }); - it('should throw an error when failed to execute runtimeCacheInputs', async (done) => { + it('should throw an error when failed to execute runtimeCacheInputs', async () => { const hasher = new Hasher( { nodes: { @@ -137,10 +135,9 @@ describe('Hasher', () => { expect(e.message).toContain('boom:'); expect(e.message).toContain(' not found'); } - done(); }); - it('should hash projects with dependencies', async (done) => { + it('should hash projects with dependencies', async () => { hashes['/filea'] = 'a.hash'; hashes['/fileb'] = 'b.hash'; const hasher = new Hasher( @@ -187,11 +184,9 @@ describe('Hasher', () => { parent: '/filea|a.hash|""|""', child: '/fileb|b.hash|""|""', }); - - done(); }); - it('should hash when circular dependencies', async (done) => { + it('should hash when circular dependencies', async () => { hashes['/filea'] = 'a.hash'; hashes['/fileb'] = 'b.hash'; const hasher = new Hasher( @@ -265,11 +260,9 @@ describe('Hasher', () => { proja: '/filea|a.hash|""|""', projb: '/fileb|b.hash|""|""', }); - - done(); }); - it('should hash implicit deps', async (done) => { + it('should hash implicit deps', async () => { hashes['/filea'] = 'a.hash'; hashes['/fileb'] = 'b.hash'; const hasher = new Hasher( @@ -319,8 +312,6 @@ describe('Hasher', () => { expect(tasksHash.value).toContain('global1.hash'); expect(tasksHash.value).toContain('global2.hash'); - - done(); }); describe('extractNameAndVersion', () => { diff --git a/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts b/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts index df266f88e6..c2ef8b2699 100644 --- a/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts +++ b/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts @@ -16,7 +16,7 @@ describe('Command Runner Builder', () => { it('should run one command', async () => { const f = fileSync().name; const result = await runCommands({ command: `echo 1 >> ${f}` }, context); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual('1'); }); @@ -26,7 +26,7 @@ describe('Command Runner Builder', () => { { command: `echo {args.key} >> ${f}`, args: '--key=123' }, context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual('123'); }); @@ -39,12 +39,12 @@ describe('Command Runner Builder', () => { }, context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual('123'); }); it('should add all args to the command if no interpolation in the command', async () => { - const exec = spyOn(require('child_process'), 'execSync').and.callThrough(); + const exec = jest.spyOn(require('child_process'), 'execSync'); await runCommands( { @@ -63,7 +63,7 @@ describe('Command Runner Builder', () => { }); it('should forward args by default when using commands (plural)', async () => { - const exec = spyOn(require('child_process'), 'exec').and.callThrough(); + const exec = jest.spyOn(require('child_process'), 'exec'); await runCommands( { @@ -82,7 +82,7 @@ describe('Command Runner Builder', () => { }); it('should forward args when forwardAllArgs is set to true', async () => { - const exec = spyOn(require('child_process'), 'exec').and.callThrough(); + const exec = jest.spyOn(require('child_process'), 'exec'); await runCommands( { @@ -101,7 +101,7 @@ describe('Command Runner Builder', () => { }); it('should not forward args when forwardAllArgs is set to false', async () => { - const exec = spyOn(require('child_process'), 'exec').and.callThrough(); + const exec = jest.spyOn(require('child_process'), 'exec'); await runCommands( { @@ -142,7 +142,7 @@ describe('Command Runner Builder', () => { }, context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual('12'); }); @@ -162,7 +162,7 @@ describe('Command Runner Builder', () => { }, context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); const contents = readFile(f); expect(contents).toContain(1); expect(contents).toContain(2); @@ -187,7 +187,7 @@ describe('Command Runner Builder', () => { } }); - it('should return success true when the string specified is ready condition is found', async (done) => { + it('should return success true when the string specified is ready condition is found', async () => { const f = fileSync().name; const result = await runCommands( { @@ -201,12 +201,11 @@ describe('Command Runner Builder', () => { }, context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual(''); setTimeout(() => { expect(readFile(f)).toEqual('1'); - done(); }, 150); }); }); @@ -229,7 +228,7 @@ describe('Command Runner Builder', () => { describe('--color', () => { it('should not set FORCE_COLOR=true', async () => { - const exec = spyOn(require('child_process'), 'exec').and.callThrough(); + const exec = jest.spyOn(require('child_process'), 'exec'); await runCommands( { commands: [ @@ -249,7 +248,7 @@ describe('Command Runner Builder', () => { }); it('should set FORCE_COLOR=true when running with --color', async () => { - const exec = spyOn(require('child_process'), 'exec').and.callThrough(); + const exec = jest.spyOn(require('child_process'), 'exec'); await runCommands( { commands: [ @@ -287,7 +286,7 @@ describe('Command Runner Builder', () => { { root } as any ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(normalize(readFile(f))).toBe(root); }); @@ -310,7 +309,7 @@ describe('Command Runner Builder', () => { { root } as any ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(normalize(readFile(f))).toBe(childFolder); }); @@ -332,7 +331,7 @@ describe('Command Runner Builder', () => { { root } as any ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(normalize(readFile(f))).toBe(childFolder); }); }); @@ -364,7 +363,7 @@ describe('Command Runner Builder', () => { context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual('https://nrwl.io/'); }); @@ -384,7 +383,7 @@ describe('Command Runner Builder', () => { context ); - expect(result).toEqual(jasmine.objectContaining({ success: true })); + expect(result).toEqual(expect.objectContaining({ success: true })); expect(readFile(f)).toEqual('https://nx.dev/'); }); diff --git a/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts b/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts index 565c598623..f2a64019de 100644 --- a/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts @@ -54,7 +54,7 @@ describe('updateEslint', () => { expect( readJson(tree, '/libs/shared/my-destination/.eslintrc.json') ).toEqual( - jasmine.objectContaining({ + expect.objectContaining({ extends: '../../../.eslintrc.json', }) ); diff --git a/packages/workspace/src/migrations/update-10-3-0/add-buildable-project-deps-in-package-json-type.spec.ts b/packages/workspace/src/migrations/update-10-3-0/add-buildable-project-deps-in-package-json-type.spec.ts index a0bad70d39..750a611b0b 100644 --- a/packages/workspace/src/migrations/update-10-3-0/add-buildable-project-deps-in-package-json-type.spec.ts +++ b/packages/workspace/src/migrations/update-10-3-0/add-buildable-project-deps-in-package-json-type.spec.ts @@ -52,7 +52,7 @@ describe('update workspace that have web and angular lib builders', () => { ); }); - it('should add `buildableProjectDepsInPackageJsonType` to specific builders', async (done) => { + it('should add `buildableProjectDepsInPackageJsonType` to specific builders', async () => { const result = await schematicRunner .runSchematicAsync( 'add-buildable-project-deps-in-package-json-type', @@ -85,7 +85,5 @@ describe('update workspace that have web and angular lib builders', () => { "builder": "@nrwl/node:package", } `); - - done(); }); }); diff --git a/packages/workspace/src/tasks-runner/run-command.spec.ts b/packages/workspace/src/tasks-runner/run-command.spec.ts index 92db1c2c57..599d56acce 100644 --- a/packages/workspace/src/tasks-runner/run-command.spec.ts +++ b/packages/workspace/src/tasks-runner/run-command.spec.ts @@ -331,7 +331,9 @@ describe('createTasksForProjectToRun', () => { }); it('should throw an error for an invalid target', () => { - spyOn(process, 'exit').and.throwError(''); + jest.spyOn(process, 'exit').mockImplementation(() => { + throw new Error(); + }); try { createTasksForProjectToRun( [projectGraph.nodes.app1], @@ -350,7 +352,9 @@ describe('createTasksForProjectToRun', () => { }); it('should throw an error for an invalid configuration for the initiating project', () => { - spyOn(process, 'exit').and.throwError(''); + jest.spyOn(process, 'exit').mockImplementation(() => { + throw new Error(); + }); try { createTasksForProjectToRun( [projectGraph.nodes.app1], @@ -391,7 +395,9 @@ describe('createTasksForProjectToRun', () => { source: 'lib1', target: 'app1', }); - spyOn(process, 'exit').and.throwError(''); + jest.spyOn(process, 'exit').mockImplementation(() => { + throw new Error(); + }); try { createTasksForProjectToRun( [projectGraph.nodes.app1], @@ -416,7 +422,9 @@ describe('createTasksForProjectToRun', () => { projects: 'self', }, ]; - spyOn(process, 'exit').and.throwError(''); + jest.spyOn(process, 'exit').mockImplementation(() => { + throw new Error(); + }); try { const tasks = createTasksForProjectToRun( [projectGraph.nodes.app1], @@ -447,7 +455,9 @@ describe('createTasksForProjectToRun', () => { projects: 'self', }, ]; - spyOn(process, 'exit').and.throwError(''); + jest.spyOn(process, 'exit').mockImplementation(() => { + throw new Error(); + }); try { const tasks = createTasksForProjectToRun( [projectGraph.nodes.app1], diff --git a/packages/workspace/src/utils/rules/format-files.spec.ts b/packages/workspace/src/utils/rules/format-files.spec.ts index 9e5e486c92..0d13d6850a 100644 --- a/packages/workspace/src/utils/rules/format-files.spec.ts +++ b/packages/workspace/src/utils/rules/format-files.spec.ts @@ -14,12 +14,16 @@ describe('formatFiles', () => { '@nrwl/workspace', path.join(__dirname, '../../../collection.json') ); - spyOn(prettier, 'format').and.callFake((input) => `formatted :: ${input}`); + jest + .spyOn(prettier, 'format') + .mockImplementation((input) => `formatted :: ${input}`); tree = Tree.empty(); }); + afterEach(() => jest.clearAllMocks()); + it('should format created files', async () => { - spyOn(prettier, 'resolveConfig').and.returnValue( + jest.spyOn(prettier, 'resolveConfig').mockReturnValue( Promise.resolve({ printWidth: 80, }) @@ -36,7 +40,7 @@ describe('formatFiles', () => { }); it('should not format deleted files', async () => { - spyOn(prettier, 'resolveConfig').and.returnValue( + jest.spyOn(prettier, 'resolveConfig').mockReturnValue( Promise.resolve({ printWidth: 80, }) @@ -46,12 +50,14 @@ describe('formatFiles', () => { await schematicRunner.callRule(formatFiles(), tree).toPromise(); expect(prettier.format).not.toHaveBeenCalledWith( 'const b=b', - jasmine.anything() + expect.anything() ); }); it('should format overwritten files', async () => { - spyOn(prettier, 'resolveConfig').and.returnValue(Promise.resolve(null)); + jest + .spyOn(prettier, 'resolveConfig') + .mockReturnValue(Promise.resolve(null)); tree.create('a.ts', 'const a=a'); tree.overwrite('a.ts', 'const a=b'); const result = await schematicRunner @@ -64,7 +70,9 @@ describe('formatFiles', () => { }); it('should not format renamed files', async () => { - spyOn(prettier, 'resolveConfig').and.returnValue(Promise.resolve(null)); + jest + .spyOn(prettier, 'resolveConfig') + .mockReturnValue(Promise.resolve(null)); tree.create('a.ts', 'const a=a'); tree.rename('a.ts', 'b.ts'); const result = await schematicRunner @@ -78,7 +86,7 @@ describe('formatFiles', () => { describe('--skip-format', () => { it('should not format created files', async () => { - spyOn(prettier, 'resolveConfig').and.returnValue( + jest.spyOn(prettier, 'resolveConfig').mockReturnValue( Promise.resolve({ printWidth: 80, }) diff --git a/yarn.lock b/yarn.lock index 20ee10203e..3ab29636ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13155,6 +13155,33 @@ jest-changed-files@^26.6.2: execa "^4.0.0" throat "^5.0.0" +jest-circus@^26.6.3: + version "26.6.3" + resolved "https://registry.yarnpkg.com/jest-circus/-/jest-circus-26.6.3.tgz#3cc7ef2a6a3787e5d7bfbe2c72d83262154053e7" + integrity sha512-ACrpWZGcQMpbv13XbzRzpytEJlilP/Su0JtNCi5r/xLpOUhnaIJr8leYYpLEMgPFURZISEHrnnpmB54Q/UziPw== + dependencies: + "@babel/traverse" "^7.1.0" + "@jest/environment" "^26.6.2" + "@jest/test-result" "^26.6.2" + "@jest/types" "^26.6.2" + "@types/babel__traverse" "^7.0.4" + "@types/node" "*" + chalk "^4.0.0" + co "^4.6.0" + dedent "^0.7.0" + expect "^26.6.2" + is-generator-fn "^2.0.0" + jest-each "^26.6.2" + jest-matcher-utils "^26.6.2" + jest-message-util "^26.6.2" + jest-runner "^26.6.3" + jest-runtime "^26.6.3" + jest-snapshot "^26.6.2" + jest-util "^26.6.2" + pretty-format "^26.6.2" + stack-utils "^2.0.2" + throat "^5.0.0" + jest-cli@^26.6.3: version "26.6.3" resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-26.6.3.tgz#43117cfef24bc4cd691a174a8796a532e135e92a"