Skip to content

Commit c6bcb7b

Browse files
Luca ForstnerAbhiPrasad
authored andcommitted
assert on build
1 parent bdef6b0 commit c6bcb7b

File tree

5 files changed

+81
-7
lines changed

5 files changed

+81
-7
lines changed

packages/e2e-tests/run.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ type RecipeResult = {
174174
type Recipe = {
175175
testApplicationName: string;
176176
buildCommand?: string;
177+
buildAssertionCommand?: string;
177178
buildTimeoutSeconds?: number;
178179
tests: {
179180
testName: string;
@@ -212,9 +213,9 @@ const recipeResults: RecipeResult[] = recipePaths.map(recipePath => {
212213
console.log(buildCommandProcess.stdout.replace(/^/gm, '[BUILD OUTPUT] '));
213214
console.log(buildCommandProcess.stderr.replace(/^/gm, '[BUILD OUTPUT] '));
214215

215-
const error: undefined | (Error & { code?: string }) = buildCommandProcess.error;
216+
const buildCommandProcessError: undefined | (Error & { code?: string }) = buildCommandProcess.error;
216217

217-
if (error?.code === 'ETIMEDOUT') {
218+
if (buildCommandProcessError?.code === 'ETIMEDOUT') {
218219
processShouldExitWithError = true;
219220

220221
printCIErrorMessage(
@@ -239,6 +240,58 @@ const recipeResults: RecipeResult[] = recipePaths.map(recipePath => {
239240
testResults: [],
240241
};
241242
}
243+
244+
if (recipe.buildAssertionCommand) {
245+
console.log(
246+
`Running E2E test build assertion for test application "${recipe.testApplicationName}"${dependencyOverridesInformationString}`,
247+
);
248+
const buildAssertionCommandProcess = childProcess.spawnSync(recipe.buildAssertionCommand, {
249+
cwd: path.dirname(recipePath),
250+
input: buildCommandProcess.stdout,
251+
encoding: 'utf8',
252+
shell: true, // needed so we can pass the build command in as whole without splitting it up into args
253+
timeout: (recipe.buildTimeoutSeconds ?? DEFAULT_BUILD_TIMEOUT_SECONDS) * 1000,
254+
env: {
255+
...process.env,
256+
...envVarsToInject,
257+
},
258+
});
259+
260+
// Prepends some text to the output build command's output so we can distinguish it from logging in this script
261+
console.log(buildAssertionCommandProcess.stdout.replace(/^/gm, '[BUILD ASSERTION OUTPUT] '));
262+
console.log(buildAssertionCommandProcess.stderr.replace(/^/gm, '[BUILD ASSERTION OUTPUT] '));
263+
264+
const buildAssertionCommandProcessError: undefined | (Error & { code?: string }) =
265+
buildAssertionCommandProcess.error;
266+
267+
if (buildAssertionCommandProcessError?.code === 'ETIMEDOUT') {
268+
processShouldExitWithError = true;
269+
270+
printCIErrorMessage(
271+
`Build assertion in test application "${recipe.testApplicationName}" (${path.dirname(
272+
recipePath,
273+
)}) timed out!`,
274+
);
275+
276+
return {
277+
dependencyOverrides,
278+
buildFailed: true,
279+
testResults: [],
280+
};
281+
} else if (buildAssertionCommandProcess.status !== 0) {
282+
processShouldExitWithError = true;
283+
284+
printCIErrorMessage(
285+
`Build assertion in test application "${recipe.testApplicationName}" (${path.dirname(recipePath)}) failed!`,
286+
);
287+
288+
return {
289+
dependencyOverrides,
290+
buildFailed: true,
291+
testResults: [],
292+
};
293+
}
294+
}
242295
}
243296

244297
const testResults: TestResult[] = recipe.tests.map(test => {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as fs from 'fs';
2+
import * as assert from 'assert/strict';
3+
4+
const stdin = fs.readFileSync(0).toString();
5+
6+
// Assert that all static components stay static and ally dynamic components stay dynamic
7+
8+
assert.match(stdin, / \/client-component/);
9+
assert.match(stdin, / \/client-component\/parameter\/\[\.\.\.parameters\]/);
10+
assert.match(stdin, / \/client-component\/parameter\/\[parameter\]/);
11+
12+
assert.match(stdin, /λ \/server-component/);
13+
assert.match(stdin, /λ \/server-component\/parameter\/\[\.\.\.parameters\]/);
14+
assert.match(stdin, /λ \/server-component\/parameter\/\[parameter\]/);
15+
16+
export {};

packages/e2e-tests/test-applications/nextjs-app-dir/test-recipe.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "nextjs-13-app-dir",
44
"buildCommand": "yarn install --pure-lockfile && npx playwright install && yarn build",
5+
"buildAssertionCommand": "yarn ts-node --script-mode assert-build.ts",
56
"tests": [
67
{
78
"testName": "Prod Mode",

packages/e2e-tests/test-applications/nextjs-app-dir/tests/devErrorSymbolification.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ test.describe('dev mode error symbolification', () => {
2121

2222
expect(errorEventFrames?.[errorEventFrames?.length - 1]).toEqual(
2323
expect.objectContaining({
24+
function: 'onClick',
2425
filename: 'components/client-error-debug-tools.tsx',
2526
abs_path: 'webpack-internal:///(app-client)/./components/client-error-debug-tools.tsx',
26-
function: 'onClick',
27-
in_app: true,
28-
lineno: 32,
27+
lineno: 54,
2928
colno: 16,
30-
post_context: [' }}', ' >', ' Throw error'],
31-
context_line: " throw new Error('Click Error');",
29+
in_app: true,
3230
pre_context: [' <button', ' onClick={() => {'],
31+
context_line: " throw new Error('Click Error');",
32+
post_context: [' }}', ' >', ' Throw error'],
3333
}),
3434
);
3535
});

packages/e2e-tests/test-recipe-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"description": "Command that is run to install dependencies and build the test application. This command is only run once before all tests. Working directory of the command is the root of the test application."
1313
},
14+
"buildAssertionCommand": {
15+
"type": "string",
16+
"description": "Command to verify build output. This command will be run after the build is complete. The command will receive the STDOUT of the `buildCommand` as STDIN."
17+
},
1418
"buildTimeoutSeconds": {
1519
"type": "number",
1620
"description": "Timeout for the build command in seconds. Default: 60"

0 commit comments

Comments
 (0)