Skip to content

Commit 096ec4c

Browse files
authored
test: move fixtures to jest (#3010)
1 parent 24f6d19 commit 096ec4c

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

src/utils/stackTrace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ function parseStackFrame(frame: string): ParsedStackFrame | null {
4747

4848
export function getCallerFilePath(ignorePrefix = PLAYWRIGHT_LIB_PATH): string | null {
4949
const error = new Error();
50-
const stackFrames = (error.stack || '').split('\n').slice(1);
50+
const stackFrames = (error.stack || '').split('\n').slice(2);
5151
// Find first stackframe that doesn't point to ignorePrefix.
5252
for (const frame of stackFrames) {
5353
const parsed = parseStackFrame(frame);
5454
if (!parsed)
5555
return null;
56-
if (parsed.filePath.startsWith(ignorePrefix) || parsed.filePath === __filename)
56+
if (parsed.filePath.startsWith(ignorePrefix))
5757
continue;
5858
return parsed.filePath;
5959
}

test/fixtures.spec.js renamed to test/fixtures.jest.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,26 @@
1717

1818
const path = require('path');
1919
const {spawn, execSync} = require('child_process');
20-
const {FFOX, CHROMIUM, WEBKIT, WIN, LINUX} = require('./utils').testOptions(browserType);
20+
const {FFOX, CHROMIUM, WEBKIT, WIN, LINUX, HEADLESS} = testOptions;
21+
22+
const playwrightPath = path.join(__dirname, '..');
2123

2224
class Wrapper {
23-
constructor(state, extraOptions) {
25+
constructor(browserType, defaultBrowserOptions, extraOptions) {
2426
this._output = new Map();
2527
this._outputCallback = new Map();
2628

27-
this._browserType = state.browserType;
28-
const launchOptions = {...state.defaultBrowserOptions,
29+
this._browserType = browserType;
30+
const launchOptions = {...defaultBrowserOptions,
2931
handleSIGINT: true,
3032
handleSIGTERM: true,
3133
handleSIGHUP: true,
32-
executablePath: state.browserType.executablePath(),
34+
executablePath: browserType.executablePath(),
3335
logger: undefined,
3436
};
3537
const options = {
36-
playwrightFile: path.join(state.playwrightPath, 'index'),
37-
browserTypeName: state.browserType.name(),
38+
playwrightFile: path.join(playwrightPath, 'index'),
39+
browserTypeName: browserType.name(),
3840
launchOptions,
3941
...extraOptions,
4042
};
@@ -89,15 +91,20 @@ class Wrapper {
8991
}
9092
}
9193

92-
async function setup(state, options = {}) {
93-
const wrapper = new Wrapper(state, options);
94+
registerFixture('wrapper', async ({browserType, defaultBrowserOptions}, test) => {
95+
const wrapper = new Wrapper(browserType, defaultBrowserOptions);
9496
await wrapper.connect();
95-
return wrapper;
96-
}
97+
await test(wrapper);
98+
});
99+
100+
registerFixture('stallingWrapper', async ({browserType, defaultBrowserOptions}, test) => {
101+
const wrapper = new Wrapper(browserType, defaultBrowserOptions, { stallOnClose: true });
102+
await wrapper.connect();
103+
await test(wrapper);
104+
});
97105

98106
describe('Fixtures', function() {
99-
it.slow()('should close the browser when the node process closes', async state => {
100-
const wrapper = await setup(state);
107+
it.slow()('should close the browser when the node process closes', async ({wrapper}) => {
101108
if (WIN)
102109
execSync(`taskkill /pid ${wrapper.child().pid} /T /F`);
103110
else
@@ -107,67 +114,62 @@ describe('Fixtures', function() {
107114
// so we don't check it here.
108115
});
109116

110-
describe.skip(WIN).skip(!HEADLESS)('signals', () => {
117+
describe.skip(WIN || !HEADLESS)('signals', () => {
111118
// Cannot reliably send signals on Windows.
112-
it.slow()('should report browser close signal', async state => {
113-
const wrapper = await setup(state);
119+
it.slow()('should report browser close signal', async ({wrapper}) => {
114120
const pid = await wrapper.out('pid');
115121
process.kill(-pid, 'SIGTERM');
116122
expect(await wrapper.out('exitCode')).toBe('null');
117123
expect(await wrapper.out('signal')).toBe('SIGTERM');
118124
process.kill(wrapper.child().pid);
119125
await wrapper.childExitCode();
120126
});
121-
it.slow()('should report browser close signal 2', async state => {
122-
const wrapper = await setup(state);
127+
it.slow()('should report browser close signal 2', async ({wrapper}) => {
123128
const pid = await wrapper.out('pid');
124129
process.kill(-pid, 'SIGKILL');
125130
expect(await wrapper.out('exitCode')).toBe('null');
126131
expect(await wrapper.out('signal')).toBe('SIGKILL');
127132
process.kill(wrapper.child().pid);
128133
await wrapper.childExitCode();
129134
});
130-
it.slow()('should close the browser on SIGINT', async state => {
131-
const wrapper = await setup(state);
135+
it.slow()('should close the browser on SIGINT', async ({wrapper}) => {
132136
process.kill(wrapper.child().pid, 'SIGINT');
133137
expect(await wrapper.out('exitCode')).toBe('0');
134138
expect(await wrapper.out('signal')).toBe('null');
135139
expect(await wrapper.childExitCode()).toBe(130);
136140
});
137-
it.slow()('should close the browser on SIGTERM', async state => {
138-
const wrapper = await setup(state);
141+
it.slow()('should close the browser on SIGTERM', async ({wrapper}) => {
139142
process.kill(wrapper.child().pid, 'SIGTERM');
140143
expect(await wrapper.out('exitCode')).toBe('0');
141144
expect(await wrapper.out('signal')).toBe('null');
142145
expect(await wrapper.childExitCode()).toBe(0);
143146
});
144-
it.slow()('should close the browser on SIGHUP', async state => {
145-
const wrapper = await setup(state);
147+
it.slow()('should close the browser on SIGHUP', async ({wrapper}) => {
146148
process.kill(wrapper.child().pid, 'SIGHUP');
147149
expect(await wrapper.out('exitCode')).toBe('0');
148150
expect(await wrapper.out('signal')).toBe('null');
149151
expect(await wrapper.childExitCode()).toBe(0);
150152
});
151-
it.slow()('should kill the browser on double SIGINT', async state => {
152-
const wrapper = await setup(state, { stallOnClose: true });
153+
it.slow()('should kill the browser on double SIGINT', async ({stallingWrapper}) => {
154+
const wrapper = stallingWrapper;
153155
process.kill(wrapper.child().pid, 'SIGINT');
154156
await wrapper.out('stalled');
155157
process.kill(wrapper.child().pid, 'SIGINT');
156158
expect(await wrapper.out('exitCode')).toBe('null');
157159
expect(await wrapper.out('signal')).toBe('SIGKILL');
158160
expect(await wrapper.childExitCode()).toBe(130);
159161
});
160-
it.slow()('should kill the browser on SIGINT + SIGTERM', async state => {
161-
const wrapper = await setup(state, { stallOnClose: true });
162+
it.slow()('should kill the browser on SIGINT + SIGTERM', async ({stallingWrapper}) => {
163+
const wrapper = stallingWrapper;
162164
process.kill(wrapper.child().pid, 'SIGINT');
163165
await wrapper.out('stalled');
164166
process.kill(wrapper.child().pid, 'SIGTERM');
165167
expect(await wrapper.out('exitCode')).toBe('null');
166168
expect(await wrapper.out('signal')).toBe('SIGKILL');
167169
expect(await wrapper.childExitCode()).toBe(0);
168170
});
169-
it.slow()('should kill the browser on SIGTERM + SIGINT', async state => {
170-
const wrapper = await setup(state, { stallOnClose: true });
171+
it.slow()('should kill the browser on SIGTERM + SIGINT', async ({stallingWrapper}) => {
172+
const wrapper = stallingWrapper;
171173
process.kill(wrapper.child().pid, 'SIGTERM');
172174
await wrapper.out('stalled');
173175
process.kill(wrapper.child().pid, 'SIGINT');
@@ -179,8 +181,8 @@ describe('Fixtures', function() {
179181
});
180182

181183
describe('StackTrace', () => {
182-
it('caller file path', async state => {
183-
const stackTrace = require(path.join(state.playwrightPath, 'lib', 'utils', 'stackTrace'));
184+
it('caller file path', async ({}) => {
185+
const stackTrace = require(path.join(playwrightPath, 'lib', 'utils', 'stackTrace'));
184186
const callme = require('./fixtures/callback');
185187
const filePath = callme(() => {
186188
return stackTrace.getCallerFilePath(path.join(__dirname, 'fixtures') + path.sep);

test/test.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ module.exports = {
7272
{
7373
files: [
7474
'./defaultbrowsercontext.spec.js',
75-
'./fixtures.spec.js',
7675
],
7776
environments: [customEnvironment],
7877
},

0 commit comments

Comments
 (0)