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(
'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);
});

View File

@ -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);
});

View File

@ -35,8 +35,9 @@ function getData(): Promise<any> {
}
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', () => {

View File

@ -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);
});
});

View File

@ -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(
`<link rel="stylesheet" href="styles.css">`
);
}, 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(
`<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 () => {
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,

View File

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

View File

@ -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);
});

View File

@ -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`);

View File

@ -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', () => {

View File

@ -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,

View File

@ -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: {

View File

@ -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",

View File

@ -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',
// },

View File

@ -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',

View File

@ -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();
});
});

View File

@ -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,

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
.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();
});
});

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
.runSchematicAsync('update-10.2.0', {}, initialTree)
.toPromise();
@ -73,6 +73,5 @@ describe('update 10.2.0', () => {
jestConfig: 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
.runSchematicAsync('update-projects-property', {}, initialTree)
.toPromise();
@ -156,7 +156,5 @@ describe('update projects property', () => {
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
.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();
});
});

View File

@ -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', () => {

View File

@ -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', () => {

View File

@ -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,

View File

@ -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: {

View File

@ -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,

View File

@ -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,

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
.runSchematicAsync('update-10.2.0', {}, initialTree)
.toPromise();
@ -56,6 +56,5 @@ describe('update 10.2.0', () => {
pluginOutputPath: 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 {
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();
}
});
});

View File

@ -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 = {

View File

@ -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,

View File

@ -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')) {

View File

@ -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(
<BuildBuilderOptions>{
...testOptions,

View File

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

View File

@ -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: {

View File

@ -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

View File

@ -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', () => {

View File

@ -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/');
});

View File

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

View File

@ -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],

View File

@ -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,
})

View File

@ -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"