mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: jest config issue [WIP] (#11676)
This commit is contained in:
parent
b715e056f9
commit
3711f86dca
@ -28,16 +28,16 @@ export function setupBrowserHooks(path = ''): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await page.close();
|
await page?.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
<% if(testRunner == 'jasmine' || testRunner == 'jest') { %>
|
<% if(testRunner == 'jasmine' || testRunner == 'jest') { %>
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await browser.close();
|
await browser?.close();
|
||||||
});
|
});
|
||||||
<% } %><% if(testRunner == 'mocha' || testRunner == 'node') { %>
|
<% } %><% if(testRunner == 'mocha' || testRunner == 'node') { %>
|
||||||
after(async () => {
|
after(async () => {
|
||||||
await browser.close();
|
await browser?.close();
|
||||||
});
|
});
|
||||||
<% } %>
|
<% } %>
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
testMatch: ['<rootDir>/build/**/?(*.)+(e2e).js?(x)'],
|
testMatch: ['<rootDir>/build/**/*.e2e.js'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
spec: './e2e/build/**/*.e2e.js',
|
spec: './e2e/build/**/*.e2e.js',
|
||||||
|
timeout: 5000,
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,8 @@ class AngularProject {
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #scripts = {
|
static #scripts = testRunner => {
|
||||||
|
return {
|
||||||
// Builds the ng-schematics before running them
|
// Builds the ng-schematics before running them
|
||||||
'build:schematics': 'npm run --prefix ../../ build',
|
'build:schematics': 'npm run --prefix ../../ build',
|
||||||
// Deletes all files created by Puppeteer Ng-Schematics to avoid errors
|
// Deletes all files created by Puppeteer Ng-Schematics to avoid errors
|
||||||
@ -35,15 +36,23 @@ class AngularProject {
|
|||||||
schematics: 'schematics ../../:ng-add --dry-run=false',
|
schematics: 'schematics ../../:ng-add --dry-run=false',
|
||||||
'schematics:e2e': 'schematics ../../:e2e --dry-run=false',
|
'schematics:e2e': 'schematics ../../:e2e --dry-run=false',
|
||||||
'schematics:config': 'schematics ../../:config --dry-run=false',
|
'schematics:config': 'schematics ../../:config --dry-run=false',
|
||||||
'schematics:smoke':
|
'schematics:smoke': `schematics ../../:ng-add --dry-run=false --test-runner="${testRunner}" && ng e2e`,
|
||||||
'schematics ../../:ng-add --dry-run=false --test-runner="node" && ng e2e',
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
/** Folder name */
|
||||||
#name;
|
#name;
|
||||||
|
/** E2E test runner to use */
|
||||||
|
#runner;
|
||||||
|
|
||||||
constructor(name) {
|
constructor(runner, name) {
|
||||||
|
this.#runner = runner ?? 'node';
|
||||||
this.#name = name ?? randomUUID();
|
this.#name = name ?? randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get runner() {
|
||||||
|
return this.#runner;
|
||||||
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.#name;
|
return this.#name;
|
||||||
}
|
}
|
||||||
@ -52,11 +61,18 @@ class AngularProject {
|
|||||||
const [executable, ...args] = command.split(' ');
|
const [executable, ...args] = command.split(' ');
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const createProcess = spawn(executable, args, {
|
const createProcess = spawn(executable, args, {
|
||||||
stdio: 'inherit',
|
|
||||||
shell: true,
|
shell: true,
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createProcess.stdout.on('data', data => {
|
||||||
|
data = data
|
||||||
|
.toString()
|
||||||
|
// Replace new lines with a prefix including the test runner
|
||||||
|
.replace(/(?:\r\n?|\n)(?=.*[\r\n])/g, `\n${this.#runner} - `);
|
||||||
|
console.log(`${this.#runner} - ${data}`);
|
||||||
|
});
|
||||||
|
|
||||||
createProcess.on('error', message => {
|
createProcess.on('error', message => {
|
||||||
console.error(`Running ${command} exited with error:`, message);
|
console.error(`Running ${command} exited with error:`, message);
|
||||||
reject(message);
|
reject(message);
|
||||||
@ -82,7 +98,7 @@ class AngularProject {
|
|||||||
const packageJson = JSON.parse(await readFile(packageJsonFile));
|
const packageJson = JSON.parse(await readFile(packageJsonFile));
|
||||||
packageJson['scripts'] = {
|
packageJson['scripts'] = {
|
||||||
...packageJson['scripts'],
|
...packageJson['scripts'],
|
||||||
...AngularProject.#scripts,
|
...AngularProject.#scripts(this.#runner),
|
||||||
};
|
};
|
||||||
await writeFile(packageJsonFile, JSON.stringify(packageJson, null, 2));
|
await writeFile(packageJsonFile, JSON.stringify(packageJson, null, 2));
|
||||||
}
|
}
|
||||||
@ -128,7 +144,7 @@ export class AngularProjectSingle extends AngularProject {
|
|||||||
export class AngularProjectMulti extends AngularProject {
|
export class AngularProjectMulti extends AngularProject {
|
||||||
async createProject() {
|
async createProject() {
|
||||||
await this.executeCommand(
|
await this.executeCommand(
|
||||||
`ng new ${this.name} --create-application=false --directory=sandbox/${this.name} --skip-git`
|
`ng new ${this.name} --create-application=false --directory=sandbox/${this.name} --defaults --skip-git`
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.executeCommand(
|
await this.executeCommand(
|
||||||
|
@ -4,17 +4,69 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {ok} from 'node:assert';
|
||||||
import {execSync} from 'node:child_process';
|
import {execSync} from 'node:child_process';
|
||||||
|
import {parseArgs} from 'node:util';
|
||||||
|
|
||||||
import {AngularProjectMulti, AngularProjectSingle} from './projects.mjs';
|
import {AngularProjectMulti, AngularProjectSingle} from './projects.mjs';
|
||||||
|
|
||||||
|
const {values: args} = parseArgs({
|
||||||
|
options: {
|
||||||
|
testRunner: {
|
||||||
|
type: 'string',
|
||||||
|
short: 't',
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: 'string',
|
||||||
|
short: 'n',
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (process.env.CI) {
|
if (process.env.CI) {
|
||||||
// Need to install in CI
|
// Need to install in CI
|
||||||
execSync('npm install -g @angular/cli@latest @angular-devkit/schematics-cli');
|
execSync('npm install -g @angular/cli@latest @angular-devkit/schematics-cli');
|
||||||
|
const runners = ['node', 'jest', 'jasmine', 'mocha'];
|
||||||
|
const groups = [];
|
||||||
|
|
||||||
|
for (const runner of runners) {
|
||||||
|
groups.push([
|
||||||
|
new AngularProjectSingle(runner),
|
||||||
|
new AngularProjectMulti(runner),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const single = new AngularProjectSingle();
|
const angularProjects = await Promise.allSettled(
|
||||||
const multi = new AngularProjectMulti();
|
groups.flat().map(async project => {
|
||||||
|
return await project.create();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
ok(
|
||||||
|
angularProjects.every(project => {
|
||||||
|
return project.status === 'fulfilled';
|
||||||
|
}),
|
||||||
|
'Building of 1 or more projects failed!'
|
||||||
|
);
|
||||||
|
|
||||||
|
for await (const runnerGroup of groups) {
|
||||||
|
const smokeResults = await Promise.allSettled(
|
||||||
|
runnerGroup.map(async project => {
|
||||||
|
return await project.runSmoke();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
ok(
|
||||||
|
smokeResults.every(project => {
|
||||||
|
return project.status === 'fulfilled';
|
||||||
|
}),
|
||||||
|
`Smoke test for ${runnerGroup[0].runner} failed!`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const single = new AngularProjectSingle(args.testRunner, args.name);
|
||||||
|
const multi = new AngularProjectMulti(args.testRunner, args.name);
|
||||||
|
|
||||||
await Promise.all([single.create(), multi.create()]);
|
await Promise.all([single.create(), multi.create()]);
|
||||||
await Promise.all([single.runSmoke(), multi.runSmoke()]);
|
await Promise.all([single.runSmoke(), multi.runSmoke()]);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user