2023-02-15 23:09:31 +00:00
|
|
|
import expect from 'expect';
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-06-23 14:02:52 +00:00
|
|
|
import {
|
|
|
|
buildTestingTree,
|
|
|
|
getAngularJsonScripts,
|
|
|
|
getPackageJson,
|
2023-06-23 15:23:32 +00:00
|
|
|
setupHttpHooks,
|
2023-06-23 14:02:52 +00:00
|
|
|
} from './utils.js';
|
2022-11-09 13:52:10 +00:00
|
|
|
|
|
|
|
describe('@puppeteer/ng-schematics: ng-add', () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
setupHttpHooks();
|
2022-11-09 13:52:10 +00:00
|
|
|
|
|
|
|
it('should create base files and update to "package.json"', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const tree = await buildTestingTree('ng-add');
|
2022-11-22 13:02:24 +00:00
|
|
|
const {devDependencies, scripts} = getPackageJson(tree);
|
2022-11-23 12:10:03 +00:00
|
|
|
const {builder, configurations} = getAngularJsonScripts(tree);
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(tree.files).toContain('/e2e/tsconfig.json');
|
|
|
|
expect(tree.files).toContain('/e2e/tests/app.e2e.ts');
|
|
|
|
expect(tree.files).toContain('/e2e/tests/utils.ts');
|
2022-11-09 13:52:10 +00:00
|
|
|
expect(devDependencies).toContain('puppeteer');
|
2022-11-22 13:02:24 +00:00
|
|
|
expect(scripts['e2e']).toBe('ng e2e');
|
2022-11-23 12:10:03 +00:00
|
|
|
expect(builder).toBe('@puppeteer/ng-schematics:puppeteer');
|
|
|
|
expect(configurations).toEqual({
|
|
|
|
production: {
|
|
|
|
devServerTarget: 'sandbox:serve:production',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update create proper "ng" command for non default tester', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const tree = await buildTestingTree('ng-add', {
|
2022-11-23 12:10:03 +00:00
|
|
|
isDefaultTester: false,
|
|
|
|
});
|
|
|
|
const {scripts} = getPackageJson(tree);
|
|
|
|
const {builder} = getAngularJsonScripts(tree, false);
|
|
|
|
|
|
|
|
expect(scripts['puppeteer']).toBe('ng run sandbox:puppeteer');
|
|
|
|
expect(builder).toBe('@puppeteer/ng-schematics:puppeteer');
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should create Puppeteer config', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const {files} = await buildTestingTree('ng-add', {
|
2022-11-09 13:52:10 +00:00
|
|
|
exportConfig: true,
|
|
|
|
});
|
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(files).toContain('/.puppeteerrc.cjs');
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not create Puppeteer config', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const {files} = await buildTestingTree('ng-add', {
|
2022-11-09 13:52:10 +00:00
|
|
|
exportConfig: false,
|
|
|
|
});
|
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(files).not.toContain('/.puppeteerrc.cjs');
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should create Jasmine files and update "package.json"', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const tree = await buildTestingTree('ng-add', {
|
2022-11-09 13:52:10 +00:00
|
|
|
testingFramework: 'jasmine',
|
|
|
|
});
|
2022-11-22 13:02:24 +00:00
|
|
|
const {devDependencies} = getPackageJson(tree);
|
2022-11-23 12:10:03 +00:00
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(tree.files).toContain('/e2e/support/jasmine.json');
|
|
|
|
expect(tree.files).toContain('/e2e/helpers/babel.js');
|
2022-11-09 13:52:10 +00:00
|
|
|
expect(devDependencies).toContain('jasmine');
|
|
|
|
expect(devDependencies).toContain('@babel/core');
|
|
|
|
expect(devDependencies).toContain('@babel/register');
|
2022-11-14 08:30:49 +00:00
|
|
|
expect(devDependencies).toContain('@babel/preset-typescript');
|
2022-11-23 12:10:03 +00:00
|
|
|
expect(options['commands']).toEqual([
|
2023-08-01 11:41:42 +00:00
|
|
|
[`./node_modules/.bin/jasmine`, '--config=./e2e/support/jasmine.json'],
|
2022-11-22 13:02:24 +00:00
|
|
|
]);
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|
2022-11-11 13:38:52 +00:00
|
|
|
|
|
|
|
it('should create Jest files and update "package.json"', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const tree = await buildTestingTree('ng-add', {
|
2022-11-11 13:38:52 +00:00
|
|
|
testingFramework: 'jest',
|
|
|
|
});
|
2022-11-22 13:02:24 +00:00
|
|
|
const {devDependencies} = getPackageJson(tree);
|
2022-11-23 12:10:03 +00:00
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-11 13:38:52 +00:00
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(tree.files).toContain('/e2e/jest.config.js');
|
2022-11-11 13:38:52 +00:00
|
|
|
expect(devDependencies).toContain('jest');
|
|
|
|
expect(devDependencies).toContain('@types/jest');
|
|
|
|
expect(devDependencies).toContain('ts-jest');
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(options['commands']).toEqual([
|
|
|
|
[`./node_modules/.bin/jest`, '-c', 'e2e/jest.config.js'],
|
|
|
|
]);
|
2022-11-11 13:38:52 +00:00
|
|
|
});
|
2022-11-14 08:30:49 +00:00
|
|
|
|
2022-11-22 13:02:24 +00:00
|
|
|
it('should create Mocha files and update "package.json"', async () => {
|
2023-06-23 15:23:32 +00:00
|
|
|
const tree = await buildTestingTree('ng-add', {
|
2022-11-14 08:30:49 +00:00
|
|
|
testingFramework: 'mocha',
|
|
|
|
});
|
2022-11-22 13:02:24 +00:00
|
|
|
const {devDependencies} = getPackageJson(tree);
|
2022-11-23 12:10:03 +00:00
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-14 08:30:49 +00:00
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(tree.files).toContain('/e2e/.mocharc.js');
|
|
|
|
expect(tree.files).toContain('/e2e/babel.js');
|
2022-11-14 08:30:49 +00:00
|
|
|
expect(devDependencies).toContain('mocha');
|
|
|
|
expect(devDependencies).toContain('@types/mocha');
|
|
|
|
expect(devDependencies).toContain('@babel/core');
|
|
|
|
expect(devDependencies).toContain('@babel/register');
|
|
|
|
expect(devDependencies).toContain('@babel/preset-typescript');
|
2022-11-23 12:10:03 +00:00
|
|
|
expect(options['commands']).toEqual([
|
2023-08-01 11:41:42 +00:00
|
|
|
[`./node_modules/.bin/mocha`, '--config=./e2e/.mocharc.js'],
|
2022-11-22 13:02:24 +00:00
|
|
|
]);
|
2022-11-14 08:30:49 +00:00
|
|
|
});
|
2022-11-14 11:57:42 +00:00
|
|
|
|
2023-06-23 15:23:32 +00:00
|
|
|
it('should create Node files', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', {
|
2022-11-14 11:57:42 +00:00
|
|
|
testingFramework: 'node',
|
|
|
|
});
|
2022-11-23 12:10:03 +00:00
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-14 11:57:42 +00:00
|
|
|
|
2023-08-01 11:41:42 +00:00
|
|
|
expect(tree.files).toContain('/e2e/.gitignore');
|
|
|
|
expect(tree.files).not.toContain('/e2e/tests/app.e2e.ts');
|
|
|
|
expect(tree.files).toContain('/e2e/tests/app.test.ts');
|
2022-11-23 12:10:03 +00:00
|
|
|
expect(options['commands']).toEqual([
|
2023-08-01 11:41:42 +00:00
|
|
|
[`./node_modules/.bin/tsc`, '-p', 'e2e/tsconfig.json'],
|
2023-06-28 08:42:32 +00:00
|
|
|
['node', '--test', '--test-reporter', 'spec', 'e2e/build/'],
|
2022-11-22 13:02:24 +00:00
|
|
|
]);
|
2022-11-14 11:57:42 +00:00
|
|
|
});
|
2023-06-28 08:01:59 +00:00
|
|
|
|
|
|
|
it('should not create port option', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add');
|
|
|
|
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
expect(options['port']).toBeUndefined();
|
|
|
|
});
|
|
|
|
it('should create port option when specified', async () => {
|
|
|
|
const port = 8080;
|
|
|
|
const tree = await buildTestingTree('ng-add', {
|
|
|
|
port,
|
|
|
|
});
|
|
|
|
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
expect(options['port']).toBe(port);
|
|
|
|
});
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|