Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: add plugin event order spec (#13802)
Ross Wollman22bc16ce7dc2
diff --git a/tests/playwright-test/plugins.spec.ts b/tests/playwright-test/plugins.spec.tsnew file mode 100644index 0000000000..90a28ec526--- /dev/null+++ b/tests/playwright-test/plugins.spec.ts@@ -0,0 +1,75 @@+/**+ * 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.+ */+import fs from 'fs';+import { test, expect } from './playwright-test-fixtures';++test('event order', async ({ runInlineTest }, testInfo) => {+ const log = testInfo.outputPath('logs.txt');+ const result = await runInlineTest({+ 'log.ts': `+ import { appendFileSync } from 'fs';+ const log = (...args) => appendFileSync('${log}', args.join(' ') + '\\n');+ export default log;+ `,+ 'test.spec.ts': `+ import log from './log';+ const { test } = pwt;+ test('it works', async ({baseURL}) => {+ log('baseURL', baseURL);+ });+ `,+ 'playwright.config.ts': `+ import { myPlugin } from './plugin.ts';+ module.exports = {+ plugins: [+ myPlugin('a'),+ myPlugin('b'),+ ],+ globalSetup: 'globalSetup.ts',+ globalTeardown: 'globalTeardown.ts',+ };+ `,+ 'globalSetup.ts': `+ import log from './log';+ const setup = () => log('globalSetup');+ export default setup;+ `,+ 'globalTeardown.ts': `+ const teardown = () => log('globalTeardown');+ export default teardown;+ `,+ 'plugin.ts': `+ import log from './log';+ export const myPlugin = (name: string) => ({+ configure: async (config) => { config.use = (config.use || {}); config.use.baseURL = (config.use.baseURL || '') + name + ' | '; },+ setup: async () => log(name, 'setup'),+ teardown: async () => log(name, 'teardown'),+ });+ `,+ });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+ const logLines = await fs.promises.readFile(log, 'utf8');+ expect(logLines.split('\n')).toEqual([+ 'a setup',+ 'b setup',+ 'globalSetup',+ 'baseURL a | b | ',+ 'b teardown',+ 'a teardown',+ '',+ ]);+});