Skip to content

Commit a555cd8

Browse files
authored
test(nextjs): Streamline integration tests (#6839)
1 parent 91f447c commit a555cd8

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,30 @@ jobs:
485485
with:
486486
path: ${{ env.CACHED_BUILD_PATHS }}
487487
key: ${{ env.BUILD_CACHE_KEY }}
488+
- name: Get npm cache directory
489+
id: npm-cache-dir
490+
run: |
491+
echo "::set-output name=dir::$(npm config get cache)"
492+
- name: Get Playwright version
493+
id: playwright-version
494+
run: |
495+
echo "::set-output name=version::$(node -p "require('@playwright/test/package.json').version")"
496+
- uses: actions/cache@v3
497+
name: Check if Playwright browser is cached
498+
id: playwright-cache
499+
with:
500+
path: ${{ steps.npm-cache-dir.outputs.dir }}
501+
key: ${{ runner.os }}-Playwright-${{steps.playwright-version.outputs.version}}
502+
- name: Install Playwright browser if not cached
503+
if: steps.playwright-cache.outputs.cache-hit != 'true'
504+
continue-on-error: true # playwright needs node >= 14
505+
run: npx playwright install --with-deps
506+
env:
507+
PLAYWRIGHT_BROWSERS_PATH: ${{steps.npm-cache-dir.outputs.dir}}
508+
- name: Install OS dependencies of Playwright if cache hit
509+
if: steps.playwright-cache.outputs.cache-hit == 'true'
510+
continue-on-error: true # playwright needs node >= 14
511+
run: npx playwright install-deps
488512
- name: Run tests
489513
env:
490514
NODE_VERSION: ${{ matrix.node }}

packages/nextjs/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@
6868
"test:build": "yarn ts-node test/buildProcess/runTest.ts",
6969
"test:unit": "jest",
7070
"test:integration": "./test/run-integration-tests.sh && yarn test:types",
71-
"test:integration:ci": "run-s test:integration:clean test:integration:client:ci test:integration:server",
72-
"test:integration:prepare": "(cd test/integration && yarn build && yarn start)",
7371
"test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)",
74-
"test:integration:client": "yarn playwright install-deps && yarn playwright test test/integration/test/client/",
75-
"test:integration:client:ci": "yarn test:integration:client --browser='all' --reporter='line'",
72+
"test:integration:client": "yarn playwright test test/integration/test/client/",
7673
"test:integration:server": "export NODE_OPTIONS='--stack-trace-limit=25' && jest --config=test/integration/jest.config.js test/integration/test/server/",
7774
"test:types": "cd test/types && yarn test",
7875
"test:watch": "jest --watch",

packages/nextjs/playwright.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import * as path from 'path';
23

34
const config: PlaywrightTestConfig = {
4-
retries: 2,
5+
retries: 0, // We do not accept flakes.
56
timeout: 12000,
67
use: {
78
baseURL: 'http://localhost:3000',
89
},
910
workers: 3,
1011
webServer: {
11-
command: 'yarn test:integration:prepare',
12+
cwd: path.join(__dirname, 'test', 'integration'),
13+
command: 'yarn start',
1214
port: 3000,
1315
},
1416
};

packages/nextjs/test/integration/test/client/tracingFetch.test.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
2828
});
2929

3030
// @ts-ignore - We know that `spans` is inside Transaction envelopes
31-
expect(transaction[0].spans[0]).toMatchObject({
32-
data: { method: 'GET', url: 'http://example.com', type: 'fetch' },
33-
description: 'GET http://example.com',
34-
op: 'http.client',
35-
parent_span_id: expect.any(String),
36-
span_id: expect.any(String),
37-
start_timestamp: expect.any(Number),
38-
timestamp: expect.any(Number),
39-
trace_id: expect.any(String),
40-
status: expect.any(String),
41-
});
31+
expect(transaction[0].spans).toEqual(
32+
expect.arrayContaining([
33+
expect.objectContaining({
34+
data: { method: 'GET', url: 'http://example.com', type: 'fetch' },
35+
description: 'GET http://example.com',
36+
op: 'http.client',
37+
parent_span_id: expect.any(String),
38+
span_id: expect.any(String),
39+
start_timestamp: expect.any(Number),
40+
timestamp: expect.any(Number),
41+
trace_id: expect.any(String),
42+
status: expect.any(String),
43+
}),
44+
]),
45+
);
4246

4347
expect(await countEnvelopes(page, { url: '/fetch', envelopeType: 'transaction', timeout: 2500 })).toBe(1);
4448
});

0 commit comments

Comments
 (0)