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 {
|
2023-08-18 14:16:07 +00:00
|
|
|
MULTI_LIBRARY_OPTIONS,
|
2023-06-23 14:02:52 +00:00
|
|
|
buildTestingTree,
|
|
|
|
getAngularJsonScripts,
|
2023-08-18 14:16:07 +00:00
|
|
|
getMultiApplicationFile,
|
|
|
|
getMultiLibraryFile,
|
2023-06-23 14:02:52 +00:00
|
|
|
getPackageJson,
|
2023-08-18 09:09:26 +00:00
|
|
|
runSchematic,
|
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
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
describe('Single Project', () => {
|
|
|
|
it('should create base files and update to "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add');
|
|
|
|
const {devDependencies, scripts} = getPackageJson(tree);
|
|
|
|
const {builder, configurations} = getAngularJsonScripts(tree);
|
|
|
|
|
|
|
|
expect(tree.files).toContain('/e2e/tsconfig.json');
|
|
|
|
expect(tree.files).toContain('/e2e/tests/app.e2e.ts');
|
|
|
|
expect(tree.files).toContain('/e2e/tests/utils.ts');
|
|
|
|
expect(devDependencies).toContain('puppeteer');
|
|
|
|
expect(scripts['e2e']).toBe('ng e2e');
|
|
|
|
expect(builder).toBe('@puppeteer/ng-schematics:puppeteer');
|
|
|
|
expect(configurations).toEqual({
|
|
|
|
production: {
|
|
|
|
devServerTarget: 'sandbox:serve:production',
|
|
|
|
},
|
|
|
|
});
|
2022-11-23 12:10:03 +00:00
|
|
|
});
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should update create proper "ng" command for non default tester', async () => {
|
2023-08-18 09:09:26 +00:00
|
|
|
let tree = await buildTestingTree('ng-add', 'single');
|
|
|
|
// Re-run schematic to have e2e populated
|
|
|
|
tree = await runSchematic(tree, 'ng-add');
|
2023-08-03 11:02:25 +00:00
|
|
|
const {scripts} = getPackageJson(tree);
|
|
|
|
const {builder} = getAngularJsonScripts(tree, false);
|
2022-11-23 12:10:03 +00:00
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(scripts['puppeteer']).toBe('ng run sandbox:puppeteer');
|
|
|
|
expect(builder).toBe('@puppeteer/ng-schematics:puppeteer');
|
2022-11-23 12:10:03 +00:00
|
|
|
});
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should not create Puppeteer config', async () => {
|
2023-08-18 09:09:26 +00:00
|
|
|
const {files} = await buildTestingTree('ng-add', 'single');
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(files).not.toContain('/.puppeteerrc.cjs');
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should create Jasmine files and update "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'single', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'jasmine',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {devDependencies} = getPackageJson(tree);
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-18 12:56:12 +00:00
|
|
|
expect(tree.files).toContain('/e2e/jasmine.json');
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(devDependencies).toContain('jasmine');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('jasmine');
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
it('should create Jest files and update "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'single', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'jest',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {devDependencies} = getPackageJson(tree);
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(tree.files).toContain('/e2e/jest.config.js');
|
|
|
|
expect(devDependencies).toContain('jest');
|
|
|
|
expect(devDependencies).toContain('@types/jest');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('jest');
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should create Mocha files and update "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'single', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'mocha',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {devDependencies} = getPackageJson(tree);
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(tree.files).toContain('/e2e/.mocharc.js');
|
|
|
|
expect(devDependencies).toContain('mocha');
|
|
|
|
expect(devDependencies).toContain('@types/mocha');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('mocha');
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
it('should create Node files', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'single', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'node',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2022-11-09 13:52:10 +00:00
|
|
|
|
2023-08-03 11:02:25 +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');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('node');
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
2023-08-18 09:09:26 +00:00
|
|
|
it('should not create port value', async () => {
|
2023-08-03 11:02:25 +00:00
|
|
|
const tree = await buildTestingTree('ng-add');
|
2022-11-11 13:38:52 +00:00
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
expect(options['port']).toBeUndefined();
|
2022-11-11 13:38:52 +00:00
|
|
|
});
|
|
|
|
});
|
2022-11-14 08:30:49 +00:00
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
describe('Multi projects Application', () => {
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should create base files and update to "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'multi');
|
|
|
|
const {devDependencies, scripts} = getPackageJson(tree);
|
|
|
|
const {builder, configurations} = getAngularJsonScripts(tree);
|
2022-11-14 11:57:42 +00:00
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
expect(tree.files).toContain(
|
|
|
|
getMultiApplicationFile('e2e/tsconfig.json')
|
|
|
|
);
|
|
|
|
expect(tree.files).toContain(
|
|
|
|
getMultiApplicationFile('e2e/tests/app.e2e.ts')
|
|
|
|
);
|
|
|
|
expect(tree.files).toContain(
|
|
|
|
getMultiApplicationFile('e2e/tests/utils.ts')
|
|
|
|
);
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(devDependencies).toContain('puppeteer');
|
|
|
|
expect(scripts['e2e']).toBe('ng e2e');
|
|
|
|
expect(builder).toBe('@puppeteer/ng-schematics:puppeteer');
|
|
|
|
expect(configurations).toEqual({
|
|
|
|
production: {
|
|
|
|
devServerTarget: 'sandbox:serve:production',
|
|
|
|
},
|
|
|
|
});
|
2022-11-14 11:57:42 +00:00
|
|
|
});
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should update create proper "ng" command for non default tester', async () => {
|
2023-08-18 09:09:26 +00:00
|
|
|
let tree = await buildTestingTree('ng-add', 'multi');
|
|
|
|
// Re-run schematic to have e2e populated
|
|
|
|
tree = await runSchematic(tree, 'ng-add');
|
2023-08-03 11:02:25 +00:00
|
|
|
const {scripts} = getPackageJson(tree);
|
|
|
|
const {builder} = getAngularJsonScripts(tree, false);
|
2022-11-14 11:57:42 +00:00
|
|
|
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(scripts['puppeteer']).toBe('ng run sandbox:puppeteer');
|
|
|
|
expect(builder).toBe('@puppeteer/ng-schematics:puppeteer');
|
|
|
|
});
|
|
|
|
it('should not create Puppeteer config', async () => {
|
2023-08-18 09:09:26 +00:00
|
|
|
const {files} = await buildTestingTree('ng-add', 'multi');
|
2023-06-28 08:01:59 +00:00
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
expect(files).not.toContain(getMultiApplicationFile('.puppeteerrc.cjs'));
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(files).not.toContain('/.puppeteerrc.cjs');
|
|
|
|
});
|
|
|
|
it('should create Jasmine files and update "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'jasmine',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {devDependencies} = getPackageJson(tree);
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
expect(tree.files).toContain(getMultiApplicationFile('e2e/jasmine.json'));
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(devDependencies).toContain('jasmine');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('jasmine');
|
2023-06-28 08:01:59 +00:00
|
|
|
});
|
2023-08-03 11:02:25 +00:00
|
|
|
it('should create Jest files and update "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'jest',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {devDependencies} = getPackageJson(tree);
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
2023-06-28 08:01:59 +00:00
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
expect(tree.files).toContain(
|
|
|
|
getMultiApplicationFile('e2e/jest.config.js')
|
|
|
|
);
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(devDependencies).toContain('jest');
|
|
|
|
expect(devDependencies).toContain('@types/jest');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('jest');
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
it('should create Mocha files and update "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'mocha',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {devDependencies} = getPackageJson(tree);
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
expect(tree.files).toContain(getMultiApplicationFile('e2e/.mocharc.js'));
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(devDependencies).toContain('mocha');
|
|
|
|
expect(devDependencies).toContain('@types/mocha');
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('mocha');
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
it('should create Node files', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
2023-08-18 09:09:26 +00:00
|
|
|
testRunner: 'node',
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
|
2023-08-18 14:16:07 +00:00
|
|
|
expect(tree.files).toContain(getMultiApplicationFile('e2e/.gitignore'));
|
2023-08-03 11:02:25 +00:00
|
|
|
expect(tree.files).not.toContain(
|
2023-08-18 14:16:07 +00:00
|
|
|
getMultiApplicationFile('e2e/tests/app.e2e.ts')
|
2023-08-03 11:02:25 +00:00
|
|
|
);
|
|
|
|
expect(tree.files).toContain(
|
2023-08-18 14:16:07 +00:00
|
|
|
getMultiApplicationFile('e2e/tests/app.test.ts')
|
2023-08-03 11:02:25 +00:00
|
|
|
);
|
2023-08-18 11:30:23 +00:00
|
|
|
expect(options['testRunner']).toBe('node');
|
2023-08-03 11:02:25 +00:00
|
|
|
});
|
2023-08-18 09:09:26 +00:00
|
|
|
it('should not create port value', async () => {
|
2023-08-03 11:02:25 +00:00
|
|
|
const tree = await buildTestingTree('ng-add');
|
|
|
|
|
|
|
|
const {options} = getAngularJsonScripts(tree);
|
|
|
|
expect(options['port']).toBeUndefined();
|
|
|
|
});
|
2023-06-28 08:01:59 +00:00
|
|
|
});
|
2023-08-18 14:16:07 +00:00
|
|
|
|
|
|
|
describe('Multi projects Library', () => {
|
|
|
|
it('should create base files and update to "package.json"', async () => {
|
|
|
|
const tree = await buildTestingTree('ng-add', 'multi');
|
|
|
|
const config = getAngularJsonScripts(
|
|
|
|
tree,
|
|
|
|
true,
|
|
|
|
MULTI_LIBRARY_OPTIONS.name
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(tree.files).not.toContain(
|
|
|
|
getMultiLibraryFile('e2e/tsconfig.json')
|
|
|
|
);
|
|
|
|
expect(tree.files).not.toContain(
|
|
|
|
getMultiLibraryFile('e2e/tests/app.e2e.ts')
|
|
|
|
);
|
|
|
|
expect(tree.files).not.toContain(
|
|
|
|
getMultiLibraryFile('e2e/tests/utils.ts')
|
|
|
|
);
|
|
|
|
expect(config).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not create Puppeteer config', async () => {
|
|
|
|
const {files} = await buildTestingTree('ng-add', 'multi');
|
|
|
|
|
|
|
|
expect(files).not.toContain(getMultiLibraryFile('.puppeteerrc.cjs'));
|
|
|
|
expect(files).not.toContain('/.puppeteerrc.cjs');
|
|
|
|
});
|
|
|
|
});
|
2022-11-09 13:52:10 +00:00
|
|
|
});
|