2023-03-29 23:57:19 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-05-18 21:28:28 +03:00
|
|
|
import { test, expect, retries } from './ui-mode-fixtures';
|
2023-03-29 23:57:19 +03:00
|
|
|
|
2023-05-18 21:28:28 +03:00
|
|
|
test.describe.configure({ mode: 'parallel', retries });
|
2023-03-29 23:57:19 +03:00
|
|
|
|
|
|
|
test('should run global setup and teardown', async ({ runUITest }) => {
|
|
|
|
const { page, testProcess } = await runUITest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
import { defineConfig } from '@playwright/test';
|
|
|
|
export default defineConfig({
|
|
|
|
globalSetup: './globalSetup',
|
|
|
|
globalTeardown: './globalTeardown.ts',
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'globalSetup.ts': `
|
|
|
|
export default () => console.log('\\n%%from-global-setup');
|
|
|
|
`,
|
|
|
|
'globalTeardown.ts': `
|
|
|
|
export default () => console.log('\\n%%from-global-teardown');
|
|
|
|
`,
|
|
|
|
'a.test.js': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('should work', async ({}) => {});
|
|
|
|
`
|
|
|
|
});
|
|
|
|
await page.getByTitle('Run all').click();
|
2023-04-29 00:18:46 +03:00
|
|
|
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
2023-03-29 23:57:19 +03:00
|
|
|
await page.close();
|
2023-04-29 00:18:46 +03:00
|
|
|
await expect.poll(() => testProcess.outputLines()).toEqual([
|
2023-03-29 23:57:19 +03:00
|
|
|
'from-global-setup',
|
|
|
|
'from-global-teardown',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should teardown on sigint', async ({ runUITest }) => {
|
|
|
|
test.skip(process.platform === 'win32', 'No sending SIGINT on Windows');
|
|
|
|
const { page, testProcess } = await runUITest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
import { defineConfig } from '@playwright/test';
|
|
|
|
export default defineConfig({
|
|
|
|
globalSetup: './globalSetup',
|
|
|
|
globalTeardown: './globalTeardown.ts',
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'globalSetup.ts': `
|
|
|
|
export default () => console.log('\\n%%from-global-setup');
|
|
|
|
`,
|
|
|
|
'globalTeardown.ts': `
|
|
|
|
export default () => console.log('\\n%%from-global-teardown');
|
|
|
|
`,
|
|
|
|
'a.test.js': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('should work', async ({}) => {});
|
|
|
|
`
|
|
|
|
});
|
|
|
|
await page.getByTitle('Run all').click();
|
2023-04-29 00:18:46 +03:00
|
|
|
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
2023-03-29 23:57:19 +03:00
|
|
|
testProcess.process.kill('SIGINT');
|
2023-04-29 00:18:46 +03:00
|
|
|
await expect.poll(() => testProcess.outputLines()).toEqual([
|
2023-03-29 23:57:19 +03:00
|
|
|
'from-global-setup',
|
|
|
|
'from-global-teardown',
|
|
|
|
]);
|
|
|
|
});
|