chore(repo): use jest-circus runner

This commit is contained in:
Tasos Bekos 2021-04-16 16:19:30 +03:00 committed by Victor Savkin
parent 06c8eac002
commit 156e3c2c40
42 changed files with 271 additions and 281 deletions

View File

@ -41,7 +41,7 @@ describe('Gatsby Applications', () => {
expect(testResults.combinedOutput).toContain( expect(testResults.combinedOutput).toContain(
'Test Suites: 2 passed, 2 total' 'Test Suites: 2 passed, 2 total'
); );
}, 120000); }, 300000);
test('supports --js option', async () => { test('supports --js option', async () => {
const app = uniq('app'); const app = uniq('app');
@ -55,5 +55,5 @@ describe('Gatsby Applications', () => {
const result = runCLI(`build ${app}`); const result = runCLI(`build ${app}`);
expect(result).toContain('Done building in'); expect(result).toContain('Done building in');
}, 120000); }, 300000);
}); });

View File

@ -8,8 +8,9 @@ import {
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
describe('Jest', () => { describe('Jest', () => {
it('should be able test projects using jest', async (done) => { beforeEach(() => newProject());
newProject();
it('should be able test projects using jest', async () => {
const mylib = uniq('mylib'); const mylib = uniq('mylib');
const myapp = uniq('myapp'); const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --unit-test-runner jest`); runCLI(`generate @nrwl/angular:app ${myapp} --unit-test-runner jest`);
@ -31,11 +32,9 @@ describe('Jest', () => {
expect(libResult.combinedOutput).toContain( expect(libResult.combinedOutput).toContain(
'Test Suites: 3 passed, 3 total' 'Test Suites: 3 passed, 3 total'
); );
done(); }, 500000);
}, 45000);
it('should merge with jest config globals', async (done) => { it('should merge with jest config globals', async () => {
newProject();
const testGlobal = `'My Test Global'`; const testGlobal = `'My Test Global'`;
const mylib = uniq('mylib'); const mylib = uniq('mylib');
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
@ -71,11 +70,9 @@ describe('Jest', () => {
expect(appResult.combinedOutput).toContain( expect(appResult.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total' 'Test Suites: 1 passed, 1 total'
); );
done(); }, 90000);
}, 45000);
it('should set the NODE_ENV to `test`', async (done) => { it('should set the NODE_ENV to `test`', async () => {
newProject();
const mylib = uniq('mylib'); const mylib = uniq('mylib');
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
@ -91,11 +88,9 @@ describe('Jest', () => {
expect(appResult.combinedOutput).toContain( expect(appResult.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total' 'Test Suites: 1 passed, 1 total'
); );
done(); }, 90000);
}, 45000);
it('should support multiple `coverageReporters` through CLI', async (done) => { it('should support multiple `coverageReporters` through CLI', async () => {
newProject();
const mylib = uniq('mylib'); const mylib = uniq('mylib');
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
@ -115,6 +110,5 @@ describe('Jest', () => {
'File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s' 'File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s'
); // text ); // text
expect(result.stdout).toContain('Coverage summary'); // text-summary expect(result.stdout).toContain('Coverage summary'); // text-summary
done(); }, 90000);
}, 45000);
}); });

View File

@ -35,8 +35,9 @@ function getData(): Promise<any> {
} }
describe('Node Applications', () => { describe('Node Applications', () => {
beforeEach(() => newProject());
it('should be able to generate an empty application', async () => { it('should be able to generate an empty application', async () => {
newProject();
const nodeapp = uniq('nodeapp'); const nodeapp = uniq('nodeapp');
runCLI(`generate @nrwl/node:app ${nodeapp} --linter=eslint`); runCLI(`generate @nrwl/node:app ${nodeapp} --linter=eslint`);
@ -54,8 +55,7 @@ describe('Node Applications', () => {
expect(result).toContain('Hello World!'); expect(result).toContain('Hello World!');
}, 60000); }, 60000);
it('should be able to generate an express application', async (done) => { it('should be able to generate an express application', async () => {
newProject();
const nodeapp = uniq('nodeapp'); const nodeapp = uniq('nodeapp');
runCLI(`generate @nrwl/express:app ${nodeapp} --linter=eslint`); runCLI(`generate @nrwl/express:app ${nodeapp} --linter=eslint`);
@ -111,12 +111,10 @@ describe('Node Applications', () => {
expect(result.message).toEqual(`Welcome to ${nodeapp}!`); expect(result.message).toEqual(`Welcome to ${nodeapp}!`);
treeKill(process.pid, 'SIGTERM', (err) => { treeKill(process.pid, 'SIGTERM', (err) => {
expect(err).toBeFalsy(); expect(err).toBeFalsy();
done();
}); });
}, 120000); }, 120000);
it('should be able to generate a nest application', async (done) => { it('should be able to generate a nest application', async () => {
newProject();
const nestapp = uniq('nestapp'); const nestapp = uniq('nestapp');
runCLI(`generate @nrwl/nest:app ${nestapp} --linter=eslint`); runCLI(`generate @nrwl/nest:app ${nestapp} --linter=eslint`);
@ -166,11 +164,13 @@ describe('Node Applications', () => {
expect(result.message).toEqual(`Welcome to ${nestapp}!`); expect(result.message).toEqual(`Welcome to ${nestapp}!`);
treeKill(process.pid, 'SIGTERM', (err) => { treeKill(process.pid, 'SIGTERM', (err) => {
expect(err).toBeFalsy(); expect(err).toBeFalsy();
done();
}); });
}, 120000); }, 120000);
}); });
describe('Build Node apps', () => { describe('Build Node apps', () => {
beforeEach(() => newProject());
it('should generate a package.json with the `--generatePackageJson` flag', async () => { it('should generate a package.json with the `--generatePackageJson` flag', async () => {
newProject(); newProject();
const nestapp = uniq('nestapp'); const nestapp = uniq('nestapp');
@ -196,7 +196,7 @@ describe('Build Node apps', () => {
version: '0.0.1', version: '0.0.1',
}) })
); );
}); }, 300000);
}); });
describe('Node Libraries', () => { describe('Node Libraries', () => {
@ -215,7 +215,7 @@ describe('Node Libraries', () => {
); );
checkFilesDoNotExist(`libs/${nodelib}/package.json`); checkFilesDoNotExist(`libs/${nodelib}/package.json`);
}, 60000); }, 300000);
it('should be able to generate a publishable node library', async () => { it('should be able to generate a publishable node library', async () => {
const proj = newProject(); const proj = newProject();
@ -266,7 +266,7 @@ describe('Node Libraries', () => {
main: './src/index.js', main: './src/index.js',
typings: './src/index.d.ts', typings: './src/index.d.ts',
}); });
}, 60000); }, 300000);
it('should be able to generate a publishable node library with CLI wrapper', async () => { it('should be able to generate a publishable node library with CLI wrapper', async () => {
const proj = newProject(); const proj = newProject();
@ -298,7 +298,7 @@ describe('Node Libraries', () => {
createFile(`dist/libs/${nodeLib}/_should_keep.txt`); createFile(`dist/libs/${nodeLib}/_should_keep.txt`);
await runCLIAsync(`build ${nodeLib} --delete-output-path=false`); await runCLIAsync(`build ${nodeLib} --delete-output-path=false`);
checkFilesExist(`dist/libs/${nodeLib}/_should_keep.txt`); checkFilesExist(`dist/libs/${nodeLib}/_should_keep.txt`);
}, 60000); }, 300000);
it('should support --js flag', async () => { it('should support --js flag', async () => {
const proj = newProject(); const proj = newProject();
@ -323,7 +323,7 @@ describe('Node Libraries', () => {
`dist/libs/${nodeLib}/src/index.js`, `dist/libs/${nodeLib}/src/index.js`,
`dist/libs/${nodeLib}/package.json` `dist/libs/${nodeLib}/package.json`
); );
}, 60000); }, 300000);
it('should be able to copy assets', () => { it('should be able to copy assets', () => {
const proj = newProject(); const proj = newProject();
@ -354,7 +354,7 @@ describe('Node Libraries', () => {
runCLI(`build ${nglib}`); runCLI(`build ${nglib}`);
runCLI(`build ${nodelib}`); runCLI(`build ${nodelib}`);
checkFilesExist(`./dist/libs/${nodelib}/esm2015/index.js`); checkFilesExist(`./dist/libs/${nodelib}/esm2015/index.js`);
}, 120000); }, 300000);
it('should fail when trying to compile typescript files that are invalid', () => { it('should fail when trying to compile typescript files that are invalid', () => {
const proj = newProject(); const proj = newProject();
@ -373,10 +373,10 @@ describe('Node Libraries', () => {
}); });
describe('nest libraries', function () { describe('nest libraries', function () {
it('should be able to generate a nest library', async () => { beforeEach(() => newProject());
newProject();
const nestlib = uniq('nestlib');
it('should be able to generate a nest library', async () => {
const nestlib = uniq('nestlib');
runCLI(`generate @nrwl/nest:lib ${nestlib}`); runCLI(`generate @nrwl/nest:lib ${nestlib}`);
const jestConfigContent = readFile(`libs/${nestlib}/jest.config.js`); const jestConfigContent = readFile(`libs/${nestlib}/jest.config.js`);
@ -405,7 +405,6 @@ describe('nest libraries', function () {
}, 60000); }, 60000);
it('should be able to generate a nest library w/ service', async () => { it('should be able to generate a nest library w/ service', async () => {
newProject();
const nestlib = uniq('nestlib'); const nestlib = uniq('nestlib');
runCLI(`generate @nrwl/nest:lib ${nestlib} --service`); runCLI(`generate @nrwl/nest:lib ${nestlib} --service`);
@ -417,10 +416,9 @@ describe('nest libraries', function () {
expect(jestResult.combinedOutput).toContain( expect(jestResult.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total' 'Test Suites: 1 passed, 1 total'
); );
}, 60000); }, 200000);
it('should be able to generate a nest library w/ controller', async () => { it('should be able to generate a nest library w/ controller', async () => {
newProject();
const nestlib = uniq('nestlib'); const nestlib = uniq('nestlib');
runCLI(`generate @nrwl/nest:lib ${nestlib} --controller`); runCLI(`generate @nrwl/nest:lib ${nestlib} --controller`);
@ -432,10 +430,9 @@ describe('nest libraries', function () {
expect(jestResult.combinedOutput).toContain( expect(jestResult.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total' 'Test Suites: 1 passed, 1 total'
); );
}, 60000); }, 200000);
it('should be able to generate a nest library w/ controller and service', async () => { it('should be able to generate a nest library w/ controller and service', async () => {
newProject();
const nestlib = uniq('nestlib'); const nestlib = uniq('nestlib');
runCLI(`generate @nrwl/nest:lib ${nestlib} --controller --service`); runCLI(`generate @nrwl/nest:lib ${nestlib} --controller --service`);
@ -447,7 +444,7 @@ describe('nest libraries', function () {
expect(jestResult.combinedOutput).toContain( expect(jestResult.combinedOutput).toContain(
'Test Suites: 2 passed, 2 total' 'Test Suites: 2 passed, 2 total'
); );
}, 60000); }, 200000);
}); });
describe('with dependencies', () => { describe('with dependencies', () => {

View File

@ -11,8 +11,9 @@ import {
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
describe('Nx Plugin', () => { describe('Nx Plugin', () => {
it('should be able to generate a Nx Plugin ', async (done) => { beforeEach(() => newProject());
newProject();
it('should be able to generate a Nx Plugin ', async () => {
const plugin = uniq('plugin'); const plugin = uniq('plugin');
runCLI( runCLI(
@ -50,15 +51,13 @@ describe('Nx Plugin', () => {
}, },
}), }),
}); });
done(); }, 90000);
}, 45000);
// the test invoke ensureNxProject, which points to @nrwl/workspace collection // 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 // which walks up the directory to find it in the next repo itself, so it
// doesn't use the collection we are building // doesn't use the collection we are building
// we should change it to point to the right collection using relative path // we should change it to point to the right collection using relative path
it(`should run the plugin's e2e tests`, async (done) => { it(`should run the plugin's e2e tests`, async () => {
newProject();
const plugin = uniq('plugin-name'); const plugin = uniq('plugin-name');
runCLI( runCLI(
`generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --importPath=@proj/${plugin}` `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'); expect(results.stdout).toContain('Compiling TypeScript files');
expectTestsPass(results); expectTestsPass(results);
} }
done();
}, 250000); }, 250000);
it('should be able to generate a migration', async (done) => { it('should be able to generate a migration', async () => {
newProject();
const plugin = uniq('plugin'); const plugin = uniq('plugin');
const version = '1.0.0'; const version = '1.0.0';
@ -108,11 +104,9 @@ describe('Nx Plugin', () => {
}, },
}), }),
}); });
done(); }, 90000);
}, 45000);
it('should be able to generate a generator', async (done) => { it('should be able to generate a generator', async () => {
newProject();
const plugin = uniq('plugin'); const plugin = uniq('plugin');
const generator = uniq('generator'); const generator = uniq('generator');
@ -150,11 +144,9 @@ describe('Nx Plugin', () => {
}, },
}), }),
}); });
done(); }, 90000);
}, 45000);
it('should be able to generate a executor', async (done) => { it('should be able to generate a executor', async () => {
newProject();
const plugin = uniq('plugin'); const plugin = uniq('plugin');
const executor = uniq('executor'); const executor = uniq('executor');
@ -190,12 +182,10 @@ describe('Nx Plugin', () => {
}, },
}), }),
}); });
done(); }, 90000);
}, 45000);
describe('--directory', () => { describe('--directory', () => {
it('should create a plugin in the specified directory', () => { it('should create a plugin in the specified directory', () => {
newProject();
const plugin = uniq('plugin'); const plugin = uniq('plugin');
runCLI( runCLI(
`generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --directory subdir --importPath=@proj/${plugin}` `generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --directory subdir --importPath=@proj/${plugin}`
@ -207,17 +197,16 @@ describe('Nx Plugin', () => {
`libs/subdir/${plugin}` `libs/subdir/${plugin}`
); );
expect(workspace.projects[`subdir-${plugin}-e2e`]).toBeTruthy(); expect(workspace.projects[`subdir-${plugin}-e2e`]).toBeTruthy();
}, 45000); }, 90000);
}); });
describe('--tags', () => { describe('--tags', () => {
it('should add tags to nx.json', async () => { it('should add tags to nx.json', async () => {
newProject();
const plugin = uniq('plugin'); const plugin = uniq('plugin');
runCLI( runCLI(
`generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage --importPath=@proj/${plugin}` `generate @nrwl/nx-plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage --importPath=@proj/${plugin}`
); );
const nxJson = readJson('nx.json'); const nxJson = readJson('nx.json');
expect(nxJson.projects[plugin].tags).toEqual(['e2etag', 'e2ePackage']); expect(nxJson.projects[plugin].tags).toEqual(['e2etag', 'e2ePackage']);
}, 45000); }, 90000);
}); });
}); });

View File

@ -15,8 +15,11 @@ import {
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
describe('React Applications', () => { describe('React Applications', () => {
let proj: string;
beforeEach(() => (proj = newProject()));
it('should be able to generate a react app + lib', async () => { it('should be able to generate a react app + lib', async () => {
const proj = newProject();
const appName = uniq('app'); const appName = uniq('app');
const libName = uniq('lib'); const libName = uniq('lib');
@ -43,10 +46,9 @@ describe('React Applications', () => {
checkLinter: true, checkLinter: true,
checkE2E: true, checkE2E: true,
}); });
}, 120000); }, 500000);
it('should support vendor sourcemaps', () => { it('should support vendor sourcemaps', () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/react:app ${appName} --no-interactive`); runCLI(`generate @nrwl/react:app ${appName} --no-interactive`);
@ -66,10 +68,9 @@ describe('React Applications', () => {
runCLI(`build ${appName}`); runCLI(`build ${appName}`);
checkFilesExist(`dist/apps/${appName}/vendor.js.map`); checkFilesExist(`dist/apps/${appName}/vendor.js.map`);
}, 120000); }, 250000);
it('should be able to generate a publishable react lib', async () => { it('should be able to generate a publishable react lib', async () => {
const proj = newProject();
const libName = uniq('lib'); const libName = uniq('lib');
runCLI( runCLI(
@ -103,10 +104,9 @@ describe('React Applications', () => {
`dist/libs/${libName}/${libName}.umd.css`, `dist/libs/${libName}/${libName}.umd.css`,
`dist/libs/${libName}/${libName}.umd.js` `dist/libs/${libName}/${libName}.umd.js`
); );
}, 120000); }, 250000);
it('should be able to generate a react lib with no components', async () => { it('should be able to generate a react lib with no components', async () => {
const proj = newProject();
const appName = uniq('app'); const appName = uniq('app');
const libName = uniq('lib'); const libName = uniq('lib');
@ -130,10 +130,9 @@ describe('React Applications', () => {
checkLinter: false, checkLinter: false,
checkE2E: false, checkE2E: false,
}); });
}, 120000); }, 250000);
it('should not create a dist folder if there is an error', async () => { it('should not create a dist folder if there is an error', async () => {
const proj = newProject();
const libName = uniq('lib'); const libName = uniq('lib');
runCLI( runCLI(
@ -149,10 +148,9 @@ describe('React Applications', () => {
expect(() => { expect(() => {
checkFilesExist(`dist/libs/${libName}/package.json`); checkFilesExist(`dist/libs/${libName}/package.json`);
}).toThrow(); }).toThrow();
}, 120000); }, 250000);
it('should generate app with routing', async () => { it('should generate app with routing', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/react:app ${appName} --routing --no-interactive`); runCLI(`generate @nrwl/react:app ${appName} --routing --no-interactive`);
@ -163,11 +161,9 @@ describe('React Applications', () => {
checkLinter: false, checkLinter: false,
checkE2E: false, checkE2E: false,
}); });
}, 120000); }, 250000);
it('should generate app with different style options', async () => { it('should generate app with different style options', async () => {
newProject();
const styledComponentsApp = uniq('app'); const styledComponentsApp = uniq('app');
runCLI( runCLI(
@ -245,10 +241,9 @@ describe('React Applications', () => {
expect(readFile(`dist/apps/${noStylesApp}/index.html`)).not.toContain( expect(readFile(`dist/apps/${noStylesApp}/index.html`)).not.toContain(
`<link rel="stylesheet" href="styles.css">` `<link rel="stylesheet" href="styles.css">`
); );
}, 120000); }, 250000);
it('should generate app with legacy-ie support', async () => { it('should generate app with legacy-ie support', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/react:app ${appName} --style=css --no-interactive`); 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( expect(readFile(`dist/apps/${appName}/prod/index.html`)).toContain(
`<script src="main.esm.js" type="module"></script><script src="main.es5.js" nomodule defer></script>` `<script src="main.esm.js" type="module"></script><script src="main.es5.js" nomodule defer></script>`
); );
}, 120000); }, 250000);
it('should be able to add a redux slice', async () => { it('should be able to add a redux slice', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
const libName = uniq('lib'); const libName = uniq('lib');
@ -294,10 +288,9 @@ describe('React Applications', () => {
expect(libTestResults.combinedOutput).toContain( expect(libTestResults.combinedOutput).toContain(
'Test Suites: 2 passed, 2 total' 'Test Suites: 2 passed, 2 total'
); );
}, 120000); }, 250000);
it('should be able to use JSX', async () => { it('should be able to use JSX', async () => {
const proj = newProject();
const appName = uniq('app'); const appName = uniq('app');
const libName = uniq('lib'); const libName = uniq('lib');
@ -339,7 +332,7 @@ describe('React Applications', () => {
checkLinter: false, checkLinter: false,
checkE2E: false, checkE2E: false,
}); });
}, 30000); }, 250000);
async function testGeneratedApp( async function testGeneratedApp(
appName, appName,

View File

@ -184,7 +184,9 @@ export function removeProject({ onlyOnCI = false } = {}) {
if (onlyOnCI && !isCI) { if (onlyOnCI && !isCI) {
return; return;
} }
removeSync(tmpProjPath()); try {
removeSync(tmpProjPath());
} catch (e) {}
} }
export function runCypressTests() { export function runCypressTests() {

View File

@ -10,8 +10,9 @@ import {
import { serializeJson } from '@nrwl/workspace'; import { serializeJson } from '@nrwl/workspace';
describe('file-server', () => { describe('file-server', () => {
it('should serve folder of files', async (done) => { beforeEach(() => newProject());
newProject();
it('should serve folder of files', async () => {
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); 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 output.indexOf('Built at') > -1 && output.indexOf('Available on') > -1
); );
}); });
}, 300000);
// success, nothing to do
done();
}, 30000);
}); });

View File

@ -13,8 +13,8 @@ import {
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
describe('Web Components Applications', () => { describe('Web Components Applications', () => {
beforeEach(() => newProject());
it('should be able to generate a web app', async () => { it('should be able to generate a web app', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`);
@ -54,10 +54,9 @@ describe('Web Components Applications', () => {
const e2eResults = runCLI(`e2e ${appName}-e2e`); const e2eResults = runCLI(`e2e ${appName}-e2e`);
expect(e2eResults).toContain('All specs passed!'); expect(e2eResults).toContain('All specs passed!');
} }
}, 120000); }, 500000);
it('should remove previous output before building', async () => { it('should remove previous output before building', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
const libName = uniq('lib'); const libName = uniq('lib');
@ -90,7 +89,6 @@ describe('Web Components Applications', () => {
}, 120000); }, 120000);
it('should do another build if differential loading is needed', async () => { it('should do another build if differential loading is needed', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`);
@ -110,7 +108,6 @@ describe('Web Components Applications', () => {
}, 120000); }, 120000);
it('should emit decorator metadata when it is enabled in tsconfig', async () => { it('should emit decorator metadata when it is enabled in tsconfig', async () => {
newProject();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`); runCLI(`generate @nrwl/web:app ${appName} --no-interactive`);

View File

@ -13,7 +13,7 @@ describe('Run Commands', () => {
afterAll(() => removeProject({ onlyOnCI: true })); 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'); const nodeapp = uniq('nodeapp');
updateFile( updateFile(
`.env`, `.env`,
@ -45,10 +45,9 @@ describe('Run Commands', () => {
expect(result).not.toContain('shared-nested-value'); expect(result).not.toContain('shared-nested-value');
expect(result).toContain('root-only-value'); expect(result).toContain('root-only-value');
expect(result).toContain('nested-only-value'); expect(result).toContain('nested-only-value');
done();
}, 120000); }, 120000);
it('should pass options', async (done) => { it('should pass options', async () => {
const myapp = uniq('myapp1'); const myapp = uniq('myapp1');
runCLI(`generate @nrwl/web:app ${myapp}`); runCLI(`generate @nrwl/web:app ${myapp}`);
@ -70,10 +69,9 @@ describe('Run Commands', () => {
expect(result).toContain( expect(result).toContain(
'--var1=a --var2=b --var-hyphen=c --varCamelCase=d' '--var1=a --var2=b --var-hyphen=c --varCamelCase=d'
); );
done();
}, 120000); }, 120000);
it('should interpolate provided arguments', async (done) => { it('should interpolate provided arguments', async () => {
const myapp = uniq('myapp1'); const myapp = uniq('myapp1');
runCLI(`generate @nrwl/web:app ${myapp}`); runCLI(`generate @nrwl/web:app ${myapp}`);
@ -107,7 +105,6 @@ describe('Run Commands', () => {
expect(resultArgs).toContain('var2: b'); expect(resultArgs).toContain('var2: b');
expect(resultArgs).toContain('hyphen: c'); expect(resultArgs).toContain('hyphen: c');
expect(resultArgs).toContain('camel: d'); expect(resultArgs).toContain('camel: d');
done();
}, 120000); }, 120000);
it('should fail when a process exits non-zero', () => { it('should fail when a process exits non-zero', () => {

View File

@ -238,7 +238,7 @@ describe('format', () => {
expect(runCLI('format:check --all')).not.toContain( expect(runCLI('format:check --all')).not.toContain(
path.normalize(`apps/${myapp}/src/main.ts`) path.normalize(`apps/${myapp}/src/main.ts`)
); );
}); }, 90000);
}); });
describe('workspace-generator', () => { describe('workspace-generator', () => {
@ -449,7 +449,7 @@ describe('dep-graph', () => {
const jsonFileContents = readJson('project-graph.json'); const jsonFileContents = readJson('project-graph.json');
expect(jsonFileContents.graph.dependencies).toEqual( expect(jsonFileContents.graph.dependencies).toEqual(
jasmine.objectContaining({ expect.objectContaining({
[myapp3E2e]: [ [myapp3E2e]: [
{ {
source: myapp3E2e, source: myapp3E2e,

View File

@ -4,6 +4,7 @@ process.env.npm_config_registry = `http://localhost:4872`;
module.exports = { module.exports = {
...nxPreset, ...nxPreset,
testRunner: 'jest-circus/runner',
testTimeout: 30000, testTimeout: 30000,
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: { transform: {

View File

@ -157,6 +157,7 @@
"jasmine-marbles": "~0.6.0", "jasmine-marbles": "~0.6.0",
"jasmine-spec-reporter": "~4.2.1", "jasmine-spec-reporter": "~4.2.1",
"jest": "26.6.3", "jest": "26.6.3",
"jest-circus": "^26.6.3",
"jest-preset-angular": "8.4.0", "jest-preset-angular": "8.4.0",
"karma": "~4.0.0", "karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0", "karma-chrome-launcher": "~2.2.0",

View File

@ -152,7 +152,7 @@ describe('empty', () => {
// // assert // // assert
// expect(result.success).toBeTruthy(); // expect(result.success).toBeTruthy();
// expect(ngPackagrMock.withTsConfig).toHaveBeenCalledWith( // expect(ngPackagrMock.withTsConfig).toHaveBeenCalledWith(
// jasmine.objectContaining({ // expect.objectContaining({
// options: { // options: {
// paths: { '@proj/buildable-child': ['dist/libs/buildable-child'] }, // paths: { '@proj/buildable-child': ['dist/libs/buildable-child'] },
// }, // },
@ -184,7 +184,7 @@ describe('empty', () => {
// expect(result.success).toBeTruthy(); // expect(result.success).toBeTruthy();
// expect(fileUtils.writeJsonFile).toHaveBeenCalledWith( // expect(fileUtils.writeJsonFile).toHaveBeenCalledWith(
// 'dist/libs/buildable-parent/package.json', // 'dist/libs/buildable-parent/package.json',
// jasmine.objectContaining({ // expect.objectContaining({
// dependencies: { // dependencies: {
// '@proj/buildable-child': '1.2.3', // '@proj/buildable-child': '1.2.3',
// }, // },

View File

@ -323,7 +323,7 @@ describe('app', () => {
describe('--skipFormat', () => { describe('--skipFormat', () => {
it('should format files by default', async () => { 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); appTree = await runSchematic('app', { name: 'myApp' }, appTree);
@ -331,7 +331,7 @@ describe('app', () => {
}); });
it('should skip format when set to true', async () => { 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( appTree = await runSchematic(
'app', 'app',

View File

@ -10,8 +10,8 @@ import { installedCypressVersion } from '../../utils/cypress-version';
const Cypress = require('cypress'); const Cypress = require('cypress');
describe('Cypress builder', () => { describe('Cypress builder', () => {
let cypressRun: jasmine.Spy; let cypressRun: jest.SpyInstance;
let cypressOpen: jasmine.Spy; let cypressOpen: jest.SpyInstance;
const cypressOptions: CypressExecutorOptions = { const cypressOptions: CypressExecutorOptions = {
cypressConfig: 'apps/my-app-e2e/cypress.json', cypressConfig: 'apps/my-app-e2e/cypress.json',
parallel: false, parallel: false,
@ -47,25 +47,30 @@ describe('Cypress builder', () => {
configuration, configuration,
}; };
}; };
cypressRun = spyOn(Cypress, 'run').and.returnValue(Promise.resolve({})); cypressRun = jest
cypressOpen = spyOn(Cypress, 'open').and.returnValue(Promise.resolve({})); .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); const { success } = await cypressExecutor(cypressOptions, mockContext);
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
config: { baseUrl: 'http://localhost:4200' }, config: { baseUrl: 'http://localhost:4200' },
project: path.dirname(cypressOptions.cypressConfig), project: path.dirname(cypressOptions.cypressConfig),
}) })
); );
expect(cypressOpen).not.toHaveBeenCalled(); 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( const { success } = await cypressExecutor(
{ ...cypressOptions, headless: false, watch: true }, { ...cypressOptions, headless: false, watch: true },
mockContext mockContext
@ -73,16 +78,15 @@ describe('Cypress builder', () => {
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressOpen).toHaveBeenCalledWith( expect(cypressOpen).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
config: { baseUrl: 'http://localhost:4200' }, config: { baseUrl: 'http://localhost:4200' },
project: path.dirname(cypressOptions.cypressConfig), project: path.dirname(cypressOptions.cypressConfig),
}) })
); );
expect(cypressRun).not.toHaveBeenCalled(); 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([ (devkit as any).runExecutor = jest.fn().mockReturnValue([
{ {
success: false, success: false,
@ -92,10 +96,9 @@ describe('Cypress builder', () => {
await cypressExecutor(cypressOptions, mockContext); await cypressExecutor(cypressOptions, mockContext);
fail('Should not execute'); fail('Should not execute');
} catch (e) {} } 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); mockedInstalledCypressVersion.mockReturnValue(3);
await cypressExecutor( await cypressExecutor(
{ {
@ -106,10 +109,9 @@ describe('Cypress builder', () => {
); );
expect(devkit.logger.warn).toHaveBeenCalled(); 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); mockedInstalledCypressVersion.mockReturnValue(4);
await cypressExecutor( await cypressExecutor(
{ {
@ -120,10 +122,9 @@ describe('Cypress builder', () => {
); );
expect(devkit.logger.warn).toHaveBeenCalled(); 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -134,17 +135,16 @@ describe('Cypress builder', () => {
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
config: { config: {
baseUrl: 'http://my-distant-host.com', baseUrl: 'http://my-distant-host.com',
}, },
project: path.dirname(cypressOptions.cypressConfig), 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -154,15 +154,14 @@ describe('Cypress builder', () => {
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
browser: 'chrome', browser: 'chrome',
project: path.dirname(cypressOptions.cypressConfig), 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( const { success } = await cypressExecutor(
{ {
cypressConfig: 'apps/my-app-e2e/cypress.json', cypressConfig: 'apps/my-app-e2e/cypress.json',
@ -180,14 +179,13 @@ describe('Cypress builder', () => {
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
project: path.dirname(cypressOptions.cypressConfig), 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -197,14 +195,13 @@ describe('Cypress builder', () => {
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
ignoreTestFiles: '/some/path/to/a/file.js', 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -215,15 +212,14 @@ describe('Cypress builder', () => {
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
reporter: 'junit', reporter: 'junit',
reporterOptions: 'mochaFile=reports/results-[hash].xml,toConsole=true', 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -233,15 +229,14 @@ describe('Cypress builder', () => {
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
project: 'some/project', project: 'some/project',
configFile: 'my-cypress.json', 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -250,22 +245,28 @@ describe('Cypress builder', () => {
mockContext mockContext
); );
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun.calls.mostRecent().args[0].config.baseUrl).toBe( expect(cypressRun).toHaveBeenLastCalledWith(
'test-url-from-options' 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); const { success } = await cypressExecutor(cypressOptions, mockContext);
expect(success).toEqual(true); expect(success).toEqual(true);
expect(cypressRun.calls.mostRecent().args[0].config.baseUrl).toBe( expect(cypressRun).toHaveBeenLastCalledWith(
'http://localhost:4200' 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( const { success } = await cypressExecutor(
{ {
...cypressOptions, ...cypressOptions,
@ -277,12 +278,11 @@ describe('Cypress builder', () => {
expect(success).toEqual(true); expect(success).toEqual(true);
expect(runExecutor).not.toHaveBeenCalled(); expect(runExecutor).not.toHaveBeenCalled();
expect(cypressRun).toHaveBeenCalledWith( expect(cypressRun).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
config: { config: {
baseUrl: 'http://my-distant-host.com', baseUrl: 'http://my-distant-host.com',
}, },
}) })
); );
done();
}); });
}); });

View File

@ -74,7 +74,7 @@ describe('Jest Executor', () => {
mockContext mockContext
); );
expect(runCLI).toHaveBeenCalledWith( expect(runCLI).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
_: [], _: [],
testPathPattern: [], testPathPattern: [],
watch: false, watch: false,
@ -103,7 +103,7 @@ describe('Jest Executor', () => {
); );
expect(runCLI).toHaveBeenCalledWith( expect(runCLI).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
_: ['lib.spec.ts'], _: ['lib.spec.ts'],
coverage: false, coverage: false,
runInBand: true, runInBand: true,
@ -135,7 +135,7 @@ describe('Jest Executor', () => {
); );
expect(runCLI).toHaveBeenCalledWith( expect(runCLI).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
_: ['file1.ts', 'file2.ts'], _: ['file1.ts', 'file2.ts'],
coverage: false, coverage: false,
findRelatedTests: true, findRelatedTests: true,
@ -243,7 +243,7 @@ describe('Jest Executor', () => {
mockContext mockContext
); );
expect(runCLI).toHaveBeenCalledWith( expect(runCLI).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
_: [], _: [],
setupFilesAfterEnv: ['/root/test-setup.ts'], setupFilesAfterEnv: ['/root/test-setup.ts'],
testPathPattern: [], testPathPattern: [],
@ -279,7 +279,7 @@ describe('Jest Executor', () => {
); );
expect(runCLI).toHaveBeenCalledWith( expect(runCLI).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
_: [], _: [],
setupFilesAfterEnv: ['/root/test-setup.ts'], setupFilesAfterEnv: ['/root/test-setup.ts'],
testPathPattern: [], testPathPattern: [],
@ -312,7 +312,7 @@ describe('Jest Executor', () => {
await jestExecutor(options, mockContext); await jestExecutor(options, mockContext);
expect(runCLI).toHaveBeenCalledWith( expect(runCLI).toHaveBeenCalledWith(
jasmine.objectContaining({ expect.objectContaining({
_: [], _: [],
testPathPattern: [], testPathPattern: [],
watch: false, watch: false,

View File

@ -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 const result = await schematicRunner
.runSchematicAsync('update-10.0.0', {}, initialTree) .runSchematicAsync('update-10.0.0', {}, initialTree)
.toPromise(); .toPromise();
@ -125,10 +125,9 @@ describe('update 10.0.0', () => {
jestConfig: expect.anything(), jestConfig: expect.anything(),
passWithNoTests: 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 await schematicRunner
.runSchematicAsync('update-10.0.0', {}, initialTree) .runSchematicAsync('update-10.0.0', {}, initialTree)
.toPromise(); .toPromise();
@ -163,7 +162,5 @@ describe('update 10.0.0', () => {
const reactGlobals = reactJestObject.globals; const reactGlobals = reactJestObject.globals;
expect(reactSetupFiles).toBeUndefined(); expect(reactSetupFiles).toBeUndefined();
expect(reactGlobals).toBeUndefined(); expect(reactGlobals).toBeUndefined();
done();
}); });
}); });

View File

@ -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 const result = await schematicRunner
.runSchematicAsync('update-10.2.0', {}, initialTree) .runSchematicAsync('update-10.2.0', {}, initialTree)
.toPromise(); .toPromise();
@ -73,6 +73,5 @@ describe('update 10.2.0', () => {
jestConfig: expect.anything(), jestConfig: expect.anything(),
passWithNoTests: expect.anything(), passWithNoTests: expect.anything(),
}); });
done();
}); });
}); });

View File

@ -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 const result = await schematicRunner
.runSchematicAsync('update-projects-property', {}, initialTree) .runSchematicAsync('update-projects-property', {}, initialTree)
.toPromise(); .toPromise();
@ -156,7 +156,5 @@ describe('update projects property', () => {
displayName: 'products', displayName: 'products',
}; };
`); `);
done();
}); });
}); });

View File

@ -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 await schematicRunner
.runSchematicAsync('update-jest-preset-angular-8-4-0', {}, initialTree) .runSchematicAsync('update-jest-preset-angular-8-4-0', {}, initialTree)
.toPromise(); .toPromise();
@ -84,11 +84,9 @@ describe('update 12.1.0', () => {
'jest-preset-angular/build/serializers/ng-snapshot', 'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment', '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 await schematicRunner
.runSchematicAsync('update-jest-preset-angular-8-4-0', {}, initialTree) .runSchematicAsync('update-jest-preset-angular-8-4-0', {}, initialTree)
.toPromise(); .toPromise();
@ -99,7 +97,5 @@ describe('update 12.1.0', () => {
.trim(); .trim();
expect(testSetup).toEqual(`import 'jest-preset-angular/setup-jest';`); expect(testSetup).toEqual(`import 'jest-preset-angular/setup-jest';`);
done();
}); });
}); });

View File

@ -166,7 +166,7 @@ describe('Update jest.config.js', () => {
describe('warnings', () => { describe('warnings', () => {
beforeEach(() => { 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', () => { it('should warn when trying to add a value to an already existing object without being dot delimited', () => {

View File

@ -167,7 +167,7 @@ describe('Update jest.config.js', () => {
describe('warnings', () => { describe('warnings', () => {
beforeEach(() => { 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', () => { it('should warn when trying to add a value to an already existing object without being dot delimited', () => {

View File

@ -219,11 +219,11 @@ describe('NodeExecuteBuilder', () => {
callback(new Error('Error Message')); callback(new Error('Error Message'));
}); });
const loggerError = spyOn(logger, 'error'); const loggerError = jest.spyOn(logger, 'error');
for await (const event of executeExecutor(testOptions, context)) { 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 () => { it('should log errors from killing the process on windows', async () => {
@ -231,7 +231,7 @@ describe('NodeExecuteBuilder', () => {
callback([new Error('error'), '', 'Error Message']); callback([new Error('error'), '', 'Error Message']);
}); });
const loggerError = spyOn(logger, 'error'); const loggerError = jest.spyOn(logger, 'error');
for await (const event of executeExecutor( for await (const event of executeExecutor(
{ {
@ -241,7 +241,7 @@ describe('NodeExecuteBuilder', () => {
context 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 () => { it('should build the application and start the built file with options', async () => {
@ -263,7 +263,7 @@ describe('NodeExecuteBuilder', () => {
buildOptions = { buildOptions = {
optimization: true, optimization: true,
}; };
const loggerWarn = spyOn(logger, 'warn'); const loggerWarn = jest.spyOn(logger, 'warn');
for await (const event of executeExecutor( for await (const event of executeExecutor(
{ {
...testOptions, ...testOptions,

View File

@ -90,7 +90,7 @@ describe('NodePackageBuilder', () => {
describe('Without library dependencies', () => { describe('Without library dependencies', () => {
beforeEach(() => { beforeEach(() => {
spyOn(projectGraph, 'createProjectGraph').and.callFake(() => { jest.spyOn(projectGraph, 'createProjectGraph').mockImplementation(() => {
return { return {
nodes: { nodes: {
nodelib: { nodelib: {
@ -262,7 +262,7 @@ describe('NodePackageBuilder', () => {
describe('building with dependencies', () => { describe('building with dependencies', () => {
beforeEach(() => { beforeEach(() => {
// fake that dep project has been built // fake that dep project has been built
spyOn(projectGraph, 'createProjectGraph').and.callFake(() => { jest.spyOn(projectGraph, 'createProjectGraph').mockImplementation(() => {
return { return {
nodes: { nodes: {
nodelib: { nodelib: {

View File

@ -80,11 +80,11 @@ describe('getBaseWebpackPartial', () => {
}); });
it('should include module and main in mainFields', () => { it('should include module and main in mainFields', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: { options: {
target: 'es5', target: 'es5',
}, },
}); } as any);
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.resolve.mainFields).toContain('module'); expect(result.resolve.mainFields).toContain('module');
@ -95,7 +95,7 @@ describe('getBaseWebpackPartial', () => {
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.stats).toEqual( expect(result.stats).toEqual(
jasmine.objectContaining({ expect.objectContaining({
hash: true, hash: true,
timings: false, timings: false,
cached: false, cached: false,
@ -151,13 +151,13 @@ describe('getBaseWebpackPartial', () => {
}); });
it('should add the TsConfigPathsPlugin for resolving', () => { it('should add the TsConfigPathsPlugin for resolving', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: { options: {
paths: { paths: {
'@npmScope/libraryName': ['libs/libraryName/src/index.ts'], '@npmScope/libraryName': ['libs/libraryName/src/index.ts'],
}, },
}, },
}); } as any);
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect( expect(
result.resolve.plugins.some( result.resolve.plugins.some(
@ -167,11 +167,11 @@ describe('getBaseWebpackPartial', () => {
}); });
it('should include es2015 in mainFields if typescript is set es2015', () => { it('should include es2015 in mainFields if typescript is set es2015', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: { options: {
target: 'es2015', target: 'es2015',
}, },
}); } as any);
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.resolve.mainFields).toContain('es2015'); expect(result.resolve.mainFields).toContain('es2015');
@ -180,9 +180,9 @@ describe('getBaseWebpackPartial', () => {
describe('the file replacements option', () => { describe('the file replacements option', () => {
it('should set aliases', () => { it('should set aliases', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: {}, options: {},
}); } as any);
const result = getBaseWebpackPartial({ const result = getBaseWebpackPartial({
...input, ...input,
@ -389,7 +389,7 @@ describe('getBaseWebpackPartial', () => {
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.stats).toEqual( expect(result.stats).toEqual(
jasmine.objectContaining({ expect.objectContaining({
colors: true, colors: true,
chunks: true, chunks: true,
assets: false, assets: false,
@ -412,7 +412,7 @@ describe('getBaseWebpackPartial', () => {
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.stats).toEqual( expect(result.stats).toEqual(
jasmine.objectContaining({ expect.objectContaining({
colors: false, colors: false,
chunks: false, chunks: false,
assets: true, assets: true,

View File

@ -73,9 +73,9 @@ describe('normalizeBuildOptions', () => {
}); });
it('should normalize asset patterns', () => { it('should normalize asset patterns', () => {
spyOn(fs, 'statSync').and.returnValue({ jest.spyOn(fs, 'statSync').mockReturnValue({
isDirectory: () => true, isDirectory: () => true,
}); } as any);
const result = normalizeBuildOptions( const result = normalizeBuildOptions(
{ {
...testOptions, ...testOptions,

View File

@ -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 const result = await schematicRunner
.runSchematicAsync('update-10.2.0', {}, initialTree) .runSchematicAsync('update-10.2.0', {}, initialTree)
.toPromise(); .toPromise();
@ -56,6 +56,5 @@ describe('update 10.2.0', () => {
pluginOutputPath: expect.anything(), pluginOutputPath: expect.anything(),
jestConfig: expect.anything(), jestConfig: expect.anything(),
}); });
done();
}); });
}); });

View File

@ -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 { try {
await componentStoryGenerator(appTree, { await componentStoryGenerator(appTree, {
componentPath: 'lib/test-ui-lib.tsx', componentPath: 'lib/test-ui-lib.tsx',
@ -33,7 +33,6 @@ describe('react:component-story', () => {
expect(e.message).toContain( expect(e.message).toContain(
'Could not find any React component in file libs/test-ui-lib/src/lib/test-ui-lib.tsx' 'Could not find any React component in file libs/test-ui-lib/src/lib/test-ui-lib.tsx'
); );
done();
} }
}); });
}); });

View File

@ -39,7 +39,7 @@ describe('Build storybook', () => {
}); });
it('should call the storybook static standalone build', async () => { it('should call the storybook static standalone build', async () => {
spyOn(logger, 'info'); jest.spyOn(logger, 'info');
const uiFramework = '@storybook/angular'; const uiFramework = '@storybook/angular';
const outputPath = `${context.root}/dist/storybook`; const outputPath = `${context.root}/dist/storybook`;
const config = { const config = {

View File

@ -91,11 +91,11 @@ describe('getBaseWebpackPartial', () => {
}); });
it('should include module and main in mainFields', () => { it('should include module and main in mainFields', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: { options: {
target: 'es5', target: 'es5',
}, },
}); } as any);
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.resolve.mainFields).toContain('module'); expect(result.resolve.mainFields).toContain('module');
@ -106,7 +106,7 @@ describe('getBaseWebpackPartial', () => {
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.stats).toEqual( expect(result.stats).toEqual(
jasmine.objectContaining({ expect.objectContaining({
hash: true, hash: true,
timings: false, timings: false,
cached: false, cached: false,
@ -148,13 +148,13 @@ describe('getBaseWebpackPartial', () => {
}); });
it('should add the TsConfigPathsPlugin for resolving', () => { it('should add the TsConfigPathsPlugin for resolving', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: { options: {
paths: { paths: {
'@npmScope/libraryName': ['libs/libraryName/src/index.ts'], '@npmScope/libraryName': ['libs/libraryName/src/index.ts'],
}, },
}, },
}); } as any);
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect( expect(
result.resolve.plugins.some( result.resolve.plugins.some(
@ -171,9 +171,9 @@ describe('getBaseWebpackPartial', () => {
describe('the file replacements option', () => { describe('the file replacements option', () => {
it('should set aliases', () => { it('should set aliases', () => {
spyOn(ts, 'parseJsonConfigFileContent').and.returnValue({ jest.spyOn(ts, 'parseJsonConfigFileContent').mockReturnValue({
options: {}, options: {},
}); } as any);
const result = getBaseWebpackPartial({ const result = getBaseWebpackPartial({
...input, ...input,
@ -383,7 +383,7 @@ describe('getBaseWebpackPartial', () => {
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.stats).toEqual( expect(result.stats).toEqual(
jasmine.objectContaining({ expect.objectContaining({
colors: true, colors: true,
chunks: true, chunks: true,
assets: false, assets: false,
@ -406,7 +406,7 @@ describe('getBaseWebpackPartial', () => {
const result = getBaseWebpackPartial(input); const result = getBaseWebpackPartial(input);
expect(result.stats).toEqual( expect(result.stats).toEqual(
jasmine.objectContaining({ expect.objectContaining({
colors: false, colors: false,
chunks: false, chunks: false,
assets: true, assets: true,

View File

@ -67,7 +67,7 @@ describe('getDevServerConfig', () => {
target: 'es2015', target: 'es2015',
}; };
spyOn(ts, 'readConfigFile').and.callFake(() => ({ jest.spyOn(ts, 'readConfigFile').mockImplementation(() => ({
config: { config: {
compilerOptions: mockCompilerOptions, compilerOptions: mockCompilerOptions,
}, },
@ -135,7 +135,7 @@ describe('getDevServerConfig', () => {
}, },
}; };
spyOn(logger, 'info'); jest.spyOn(logger, 'info');
}); });
it('should print out the URL of the server', () => { it('should print out the URL of the server', () => {
@ -149,7 +149,7 @@ describe('getDevServerConfig', () => {
result.onListening(mockServer); result.onListening(mockServer);
expect(logger.info).toHaveBeenCalledWith( 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', () => { 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')) { if (path.endsWith('ssl.key')) {
return 'sslKeyContents'; return 'sslKeyContents';
} else if (path.endsWith('ssl.cert')) { } else if (path.endsWith('ssl.cert')) {

View File

@ -47,9 +47,9 @@ describe('normalizeBuildOptions', () => {
}); });
it('should normalize asset patterns', () => { it('should normalize asset patterns', () => {
spyOn(fs, 'statSync').and.returnValue({ jest.spyOn(fs, 'statSync').mockReturnValue({
isDirectory: () => true, isDirectory: () => true,
}); } as any);
const result = normalizeBuildOptions( const result = normalizeBuildOptions(
<BuildBuilderOptions>{ <BuildBuilderOptions>{
...testOptions, ...testOptions,

View File

@ -48,7 +48,7 @@ describe('getWebConfig', () => {
TsConfigPathsPlugin TsConfigPathsPlugin
)).mockImplementation(function MockPathsPlugin() {}); )).mockImplementation(function MockPathsPlugin() {});
spyOn(ts, 'readConfigFile').and.callFake(() => ({ jest.spyOn(ts, 'readConfigFile').mockImplementation(() => ({
config: { config: {
compilerOptions: mockCompilerOptions, compilerOptions: mockCompilerOptions,
}, },

View File

@ -35,9 +35,9 @@ describe('WorkspacesResults', () => {
}); });
it('should remove results from file system', () => { it('should remove results from file system', () => {
spyOn(fs, 'writeSync'); jest.spyOn(fs, 'writeSync');
spyOn(fs, 'unlinkSync'); jest.spyOn(fs, 'unlinkSync').mockImplementationOnce(() => {});
spyOn(fs, 'existsSync').and.returnValue(true); jest.spyOn(fs, 'existsSync').mockReturnValue(true);
results.setResult('proj', true); results.setResult('proj', true);
results.saveResults(); results.saveResults();
@ -57,11 +57,11 @@ describe('WorkspacesResults', () => {
describe('when results already exist', () => { describe('when results already exist', () => {
beforeEach(() => { beforeEach(() => {
spyOn(fs, 'existsSync').and.returnValue(true); jest.spyOn(fs, 'existsSync').mockReturnValue(true);
}); });
it('should read existing results', () => { it('should read existing results', () => {
spyOn(fs, 'readFileSync').and.returnValue( jest.spyOn(fs, 'readFileSync').mockReturnValue(
serializeJson({ serializeJson({
command: 'test', command: 'test',
results: { results: {
@ -84,7 +84,7 @@ describe('WorkspacesResults', () => {
}); });
it('should handle a corrupted results file', () => { it('should handle a corrupted results file', () => {
spyOn(fs, 'readFileSync').and.returnValue('invalid json'); jest.spyOn(fs, 'readFileSync').mockReturnValue('invalid json');
const runTests = () => { const runTests = () => {
results = new WorkspaceResults('test', { results = new WorkspaceResults('test', {
@ -103,7 +103,7 @@ describe('WorkspacesResults', () => {
}); });
it('should not read the existing results when the previous command was different', () => { it('should not read the existing results when the previous command was different', () => {
spyOn(fs, 'readFileSync').and.returnValue( jest.spyOn(fs, 'readFileSync').mockReturnValue(
serializeJson({ serializeJson({
command: 'test', command: 'test',
results: { results: {
@ -126,7 +126,7 @@ describe('WorkspacesResults', () => {
}); });
it('should invalidate existing results when the project is not run', () => { it('should invalidate existing results when the project is not run', () => {
spyOn(fs, 'readFileSync').and.returnValue( jest.spyOn(fs, 'readFileSync').mockReturnValue(
serializeJson({ serializeJson({
command: 'test', command: 'test',
results: { results: {

View File

@ -48,7 +48,7 @@ describe('assertWorkspaceValidity', () => {
}); });
it('should throw for a missing project in workspace.json', () => { it('should throw for a missing project in workspace.json', () => {
spyOn(output, 'error'); jest.spyOn(output, 'error');
delete mockWorkspaceJson.projects.app1; delete mockWorkspaceJson.projects.app1;
const mockExit = jest const mockExit = jest
@ -67,7 +67,7 @@ describe('assertWorkspaceValidity', () => {
}); });
it('should throw for a missing project in nx.json', () => { it('should throw for a missing project in nx.json', () => {
spyOn(output, 'error'); jest.spyOn(output, 'error');
delete mockNxJson.projects.app1; delete mockNxJson.projects.app1;
@ -87,7 +87,7 @@ describe('assertWorkspaceValidity', () => {
}); });
it('should throw for an invalid top-level implicit dependency', () => { it('should throw for an invalid top-level implicit dependency', () => {
spyOn(output, 'error'); jest.spyOn(output, 'error');
mockNxJson.implicitDependencies = { mockNxJson.implicitDependencies = {
'README.md': ['invalidproj'], 'README.md': ['invalidproj'],
}; };
@ -110,7 +110,7 @@ describe('assertWorkspaceValidity', () => {
}); });
it('should throw for an invalid project-level implicit dependency', () => { it('should throw for an invalid project-level implicit dependency', () => {
spyOn(output, 'error'); jest.spyOn(output, 'error');
mockNxJson.projects.app2.implicitDependencies = ['invalidproj']; mockNxJson.projects.app2.implicitDependencies = ['invalidproj'];
const mockExit = jest const mockExit = jest
@ -131,7 +131,7 @@ describe('assertWorkspaceValidity', () => {
}); });
it('should throw for a project-level implicit dependency that is a string', () => { 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'; mockNxJson.implicitDependencies['nx.json'] = 'invalidproj';
const mockExit = jest const mockExit = jest

View File

@ -24,7 +24,7 @@ describe('Hasher', () => {
}; };
} }
it('should create project hash', async (done) => { it('should create project hash', async () => {
fs.readFileSync = (file) => { fs.readFileSync = (file) => {
if (file === 'workspace.json') { if (file === 'workspace.json') {
return JSON.stringify({ return JSON.stringify({
@ -93,11 +93,9 @@ describe('Hasher', () => {
'echo runtime123': 'runtime123', 'echo runtime123': 'runtime123',
'echo runtime456': 'runtime456', '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( const hasher = new Hasher(
{ {
nodes: { nodes: {
@ -137,10 +135,9 @@ describe('Hasher', () => {
expect(e.message).toContain('boom:'); expect(e.message).toContain('boom:');
expect(e.message).toContain(' not found'); 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['/filea'] = 'a.hash';
hashes['/fileb'] = 'b.hash'; hashes['/fileb'] = 'b.hash';
const hasher = new Hasher( const hasher = new Hasher(
@ -187,11 +184,9 @@ describe('Hasher', () => {
parent: '/filea|a.hash|""|""', parent: '/filea|a.hash|""|""',
child: '/fileb|b.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['/filea'] = 'a.hash';
hashes['/fileb'] = 'b.hash'; hashes['/fileb'] = 'b.hash';
const hasher = new Hasher( const hasher = new Hasher(
@ -265,11 +260,9 @@ describe('Hasher', () => {
proja: '/filea|a.hash|""|""', proja: '/filea|a.hash|""|""',
projb: '/fileb|b.hash|""|""', projb: '/fileb|b.hash|""|""',
}); });
done();
}); });
it('should hash implicit deps', async (done) => { it('should hash implicit deps', async () => {
hashes['/filea'] = 'a.hash'; hashes['/filea'] = 'a.hash';
hashes['/fileb'] = 'b.hash'; hashes['/fileb'] = 'b.hash';
const hasher = new Hasher( const hasher = new Hasher(
@ -319,8 +312,6 @@ describe('Hasher', () => {
expect(tasksHash.value).toContain('global1.hash'); expect(tasksHash.value).toContain('global1.hash');
expect(tasksHash.value).toContain('global2.hash'); expect(tasksHash.value).toContain('global2.hash');
done();
}); });
describe('extractNameAndVersion', () => { describe('extractNameAndVersion', () => {

View File

@ -16,7 +16,7 @@ describe('Command Runner Builder', () => {
it('should run one command', async () => { it('should run one command', async () => {
const f = fileSync().name; const f = fileSync().name;
const result = await runCommands({ command: `echo 1 >> ${f}` }, context); 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'); expect(readFile(f)).toEqual('1');
}); });
@ -26,7 +26,7 @@ describe('Command Runner Builder', () => {
{ command: `echo {args.key} >> ${f}`, args: '--key=123' }, { command: `echo {args.key} >> ${f}`, args: '--key=123' },
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('123'); expect(readFile(f)).toEqual('123');
}); });
@ -39,12 +39,12 @@ describe('Command Runner Builder', () => {
}, },
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('123'); expect(readFile(f)).toEqual('123');
}); });
it('should add all args to the command if no interpolation in the command', async () => { 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( await runCommands(
{ {
@ -63,7 +63,7 @@ describe('Command Runner Builder', () => {
}); });
it('should forward args by default when using commands (plural)', async () => { 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( await runCommands(
{ {
@ -82,7 +82,7 @@ describe('Command Runner Builder', () => {
}); });
it('should forward args when forwardAllArgs is set to true', async () => { 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( await runCommands(
{ {
@ -101,7 +101,7 @@ describe('Command Runner Builder', () => {
}); });
it('should not forward args when forwardAllArgs is set to false', async () => { 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( await runCommands(
{ {
@ -142,7 +142,7 @@ describe('Command Runner Builder', () => {
}, },
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('12'); expect(readFile(f)).toEqual('12');
}); });
@ -162,7 +162,7 @@ describe('Command Runner Builder', () => {
}, },
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
const contents = readFile(f); const contents = readFile(f);
expect(contents).toContain(1); expect(contents).toContain(1);
expect(contents).toContain(2); 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 f = fileSync().name;
const result = await runCommands( const result = await runCommands(
{ {
@ -201,12 +201,11 @@ describe('Command Runner Builder', () => {
}, },
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual(''); expect(readFile(f)).toEqual('');
setTimeout(() => { setTimeout(() => {
expect(readFile(f)).toEqual('1'); expect(readFile(f)).toEqual('1');
done();
}, 150); }, 150);
}); });
}); });
@ -229,7 +228,7 @@ describe('Command Runner Builder', () => {
describe('--color', () => { describe('--color', () => {
it('should not set FORCE_COLOR=true', async () => { 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( await runCommands(
{ {
commands: [ commands: [
@ -249,7 +248,7 @@ describe('Command Runner Builder', () => {
}); });
it('should set FORCE_COLOR=true when running with --color', async () => { 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( await runCommands(
{ {
commands: [ commands: [
@ -287,7 +286,7 @@ describe('Command Runner Builder', () => {
{ root } as any { root } as any
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(normalize(readFile(f))).toBe(root); expect(normalize(readFile(f))).toBe(root);
}); });
@ -310,7 +309,7 @@ describe('Command Runner Builder', () => {
{ root } as any { root } as any
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(normalize(readFile(f))).toBe(childFolder); expect(normalize(readFile(f))).toBe(childFolder);
}); });
@ -332,7 +331,7 @@ describe('Command Runner Builder', () => {
{ root } as any { root } as any
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(normalize(readFile(f))).toBe(childFolder); expect(normalize(readFile(f))).toBe(childFolder);
}); });
}); });
@ -364,7 +363,7 @@ describe('Command Runner Builder', () => {
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('https://nrwl.io/'); expect(readFile(f)).toEqual('https://nrwl.io/');
}); });
@ -384,7 +383,7 @@ describe('Command Runner Builder', () => {
context context
); );
expect(result).toEqual(jasmine.objectContaining({ success: true })); expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('https://nx.dev/'); expect(readFile(f)).toEqual('https://nx.dev/');
}); });

View File

@ -54,7 +54,7 @@ describe('updateEslint', () => {
expect( expect(
readJson(tree, '/libs/shared/my-destination/.eslintrc.json') readJson(tree, '/libs/shared/my-destination/.eslintrc.json')
).toEqual( ).toEqual(
jasmine.objectContaining({ expect.objectContaining({
extends: '../../../.eslintrc.json', extends: '../../../.eslintrc.json',
}) })
); );

View File

@ -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 const result = await schematicRunner
.runSchematicAsync( .runSchematicAsync(
'add-buildable-project-deps-in-package-json-type', '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", "builder": "@nrwl/node:package",
} }
`); `);
done();
}); });
}); });

View File

@ -331,7 +331,9 @@ describe('createTasksForProjectToRun', () => {
}); });
it('should throw an error for an invalid target', () => { it('should throw an error for an invalid target', () => {
spyOn(process, 'exit').and.throwError(''); jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error();
});
try { try {
createTasksForProjectToRun( createTasksForProjectToRun(
[projectGraph.nodes.app1], [projectGraph.nodes.app1],
@ -350,7 +352,9 @@ describe('createTasksForProjectToRun', () => {
}); });
it('should throw an error for an invalid configuration for the initiating project', () => { 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 { try {
createTasksForProjectToRun( createTasksForProjectToRun(
[projectGraph.nodes.app1], [projectGraph.nodes.app1],
@ -391,7 +395,9 @@ describe('createTasksForProjectToRun', () => {
source: 'lib1', source: 'lib1',
target: 'app1', target: 'app1',
}); });
spyOn(process, 'exit').and.throwError(''); jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error();
});
try { try {
createTasksForProjectToRun( createTasksForProjectToRun(
[projectGraph.nodes.app1], [projectGraph.nodes.app1],
@ -416,7 +422,9 @@ describe('createTasksForProjectToRun', () => {
projects: 'self', projects: 'self',
}, },
]; ];
spyOn(process, 'exit').and.throwError(''); jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error();
});
try { try {
const tasks = createTasksForProjectToRun( const tasks = createTasksForProjectToRun(
[projectGraph.nodes.app1], [projectGraph.nodes.app1],
@ -447,7 +455,9 @@ describe('createTasksForProjectToRun', () => {
projects: 'self', projects: 'self',
}, },
]; ];
spyOn(process, 'exit').and.throwError(''); jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error();
});
try { try {
const tasks = createTasksForProjectToRun( const tasks = createTasksForProjectToRun(
[projectGraph.nodes.app1], [projectGraph.nodes.app1],

View File

@ -14,12 +14,16 @@ describe('formatFiles', () => {
'@nrwl/workspace', '@nrwl/workspace',
path.join(__dirname, '../../../collection.json') path.join(__dirname, '../../../collection.json')
); );
spyOn(prettier, 'format').and.callFake((input) => `formatted :: ${input}`); jest
.spyOn(prettier, 'format')
.mockImplementation((input) => `formatted :: ${input}`);
tree = Tree.empty(); tree = Tree.empty();
}); });
afterEach(() => jest.clearAllMocks());
it('should format created files', async () => { it('should format created files', async () => {
spyOn(prettier, 'resolveConfig').and.returnValue( jest.spyOn(prettier, 'resolveConfig').mockReturnValue(
Promise.resolve({ Promise.resolve({
printWidth: 80, printWidth: 80,
}) })
@ -36,7 +40,7 @@ describe('formatFiles', () => {
}); });
it('should not format deleted files', async () => { it('should not format deleted files', async () => {
spyOn(prettier, 'resolveConfig').and.returnValue( jest.spyOn(prettier, 'resolveConfig').mockReturnValue(
Promise.resolve({ Promise.resolve({
printWidth: 80, printWidth: 80,
}) })
@ -46,12 +50,14 @@ describe('formatFiles', () => {
await schematicRunner.callRule(formatFiles(), tree).toPromise(); await schematicRunner.callRule(formatFiles(), tree).toPromise();
expect(prettier.format).not.toHaveBeenCalledWith( expect(prettier.format).not.toHaveBeenCalledWith(
'const b=b', 'const b=b',
jasmine.anything() expect.anything()
); );
}); });
it('should format overwritten files', async () => { 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.create('a.ts', 'const a=a');
tree.overwrite('a.ts', 'const a=b'); tree.overwrite('a.ts', 'const a=b');
const result = await schematicRunner const result = await schematicRunner
@ -64,7 +70,9 @@ describe('formatFiles', () => {
}); });
it('should not format renamed files', async () => { 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.create('a.ts', 'const a=a');
tree.rename('a.ts', 'b.ts'); tree.rename('a.ts', 'b.ts');
const result = await schematicRunner const result = await schematicRunner
@ -78,7 +86,7 @@ describe('formatFiles', () => {
describe('--skip-format', () => { describe('--skip-format', () => {
it('should not format created files', async () => { it('should not format created files', async () => {
spyOn(prettier, 'resolveConfig').and.returnValue( jest.spyOn(prettier, 'resolveConfig').mockReturnValue(
Promise.resolve({ Promise.resolve({
printWidth: 80, printWidth: 80,
}) })

View File

@ -13155,6 +13155,33 @@ jest-changed-files@^26.6.2:
execa "^4.0.0" execa "^4.0.0"
throat "^5.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: jest-cli@^26.6.3:
version "26.6.3" version "26.6.3"
resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-26.6.3.tgz#43117cfef24bc4cd691a174a8796a532e135e92a" resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-26.6.3.tgz#43117cfef24bc4cd691a174a8796a532e135e92a"