chore: restore component testing options (#13910)

This commit is contained in:
Pavel Feldman 2022-05-03 14:48:46 -08:00 committed by GitHub
parent 29fd1d86df
commit 13224d1c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 103 additions and 87 deletions

View file

@ -1,4 +1,4 @@
import { PlaywrightTestConfig, devices } from '@playwright/test'; import { type PlaywrightTestConfig, devices } from '@playwright/experimental-ct-vue';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import Counter from './Counter.vue' import Counter from './Counter.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import Counter from './Counter.vue' import Counter from './Counter.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import HelloWorld from './HelloWorld.vue' import HelloWorld from './HelloWorld.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import HelloWorld from './HelloWorld.vue' import HelloWorld from './HelloWorld.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import NamedSlots from './NamedSlots.vue' import NamedSlots from './NamedSlots.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import NamedSlots from './NamedSlots.vue' import NamedSlots from './NamedSlots.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import DocumentationIcon from './icons/IconDocumentation.vue' import DocumentationIcon from './icons/IconDocumentation.vue'
import WelcomeItem from './WelcomeItem.vue' import WelcomeItem from './WelcomeItem.vue'

View file

@ -14,20 +14,17 @@
* limitations under the License. * limitations under the License.
*/ */
import type { PlaywrightTestConfig } from '@playwright/test';
import path from 'path'; import path from 'path';
import { devices } from '@playwright/test'; import type { PlaywrightTestConfig } from '@playwright/experimental-ct-react';
import { devices } from '@playwright/experimental-ct-react';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',
forbidOnly: !!process.env.CI, forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0, retries: process.env.CI ? 2 : 0,
reporter: process.env.CI ? [ reporter: 'html',
['html', { open: 'never' }],
] : [
['html', { open: 'on-failure' }]
],
use: { use: {
vitePort: 3101,
trace: 'on-first-retry', trace: 'on-first-retry',
}, },
projects: [ ], projects: [ ],

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { expect, test } from '@playwright/experimental-ct-react/test'; import { expect, test } from '@playwright/experimental-ct-react';
import { AutoChip, Chip as LocalChip } from './chip'; import { AutoChip, Chip as LocalChip } from './chip';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { test, expect } from '@playwright/experimental-ct-react/test'; import { test, expect } from '@playwright/experimental-ct-react';
import { HeaderView } from './headerView'; import { HeaderView } from './headerView';
test.use({ viewport: { width: 720, height: 200 } }); test.use({ viewport: { width: 720, height: 200 } });

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { test, expect } from '@playwright/experimental-ct-react/test'; import { test, expect } from '@playwright/experimental-ct-react';
import type { ImageDiff } from './imageDiffView'; import type { ImageDiff } from './imageDiffView';
import { ImageDiffView } from './imageDiffView'; import { ImageDiffView } from './imageDiffView';

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { test, expect } from '@playwright/experimental-ct-react/test'; import { test, expect } from '@playwright/experimental-ct-react';
import { TestCaseView } from './testCaseView'; import { TestCaseView } from './testCaseView';
import type { TestCase, TestResult } from '../../playwright-test/src/reporters/html'; import type { TestCase, TestResult } from '../../playwright-test/src/reporters/html';

View file

@ -4,7 +4,5 @@
!LICENSE !LICENSE
!register.d.ts !register.d.ts
!register.mjs !register.mjs
!test.d.ts !index.d.ts
!test.js !index.js
!vitePlugin.d.ts
!vitePlugin.js

View file

@ -17,11 +17,17 @@
import type { import type {
TestType, TestType,
PlaywrightTestArgs, PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions, PlaywrightTestOptions,
PlaywrightWorkerArgs, PlaywrightWorkerArgs,
PlaywrightWorkerOptions, PlaywrightWorkerOptions,
Locator, Locator,
} from '@playwright/test'; } from '@playwright/test';
import type { InlineConfig } from 'vite';
export type PlaywrightTestConfig = Omit<BasePlaywrightTestConfig, 'use'> & {
use: BasePlaywrightTestConfig['use'] & { vitePort?: number, viteConfig?: InlineConfig }
};
interface ComponentFixtures { interface ComponentFixtures {
mount(component: JSX.Element): Promise<Locator>; mount(component: JSX.Element): Promise<Locator>;
@ -31,4 +37,4 @@ export const test: TestType<
PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures, PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures,
PlaywrightWorkerArgs & PlaywrightWorkerOptions>; PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
export { expect } from '@playwright/test'; export { expect, devices } from '@playwright/test';

View file

@ -14,13 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
const { test: baseTest, expect, _addRunnerPlugin } = require('@playwright/test'); const { test: baseTest, expect, devices, _addRunnerPlugin } = require('@playwright/test');
const { mount } = require('@playwright/test/lib/mount'); const { mount } = require('@playwright/test/lib/mount');
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
_addRunnerPlugin(createPlugin( _addRunnerPlugin(() => {
'@playwright/experimental-ct-react/register', // Only fetch upon request to avoid resolution in workers.
() => require('@vitejs/plugin-react')())); const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
'@playwright/experimental-ct-react/register',
() => require('@vitejs/plugin-react')());
});
const test = baseTest.extend({ const test = baseTest.extend({
_workerPage: [async ({ browser }, use) => { _workerPage: [async ({ browser }, use) => {
@ -45,4 +48,4 @@ const test = baseTest.extend({
}, },
}); });
module.exports = { test, expect }; module.exports = { test, expect, devices };

View file

@ -14,7 +14,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"exports": { "exports": {
"./register": "./register.mjs", "./register": "./register.mjs",
"./test": "./test.js" ".": "./index.js"
}, },
"dependencies": { "dependencies": {
"@vitejs/plugin-react": "^1.0.7", "@vitejs/plugin-react": "^1.0.7",

View file

@ -4,7 +4,5 @@
!LICENSE !LICENSE
!register.d.ts !register.d.ts
!register.mjs !register.mjs
!test.d.ts !index.d.ts
!test.js !index.js
!vitePlugin.d.ts
!vitePlugin.js

View file

@ -17,11 +17,17 @@
import type { import type {
TestType, TestType,
PlaywrightTestArgs, PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions, PlaywrightTestOptions,
PlaywrightWorkerArgs, PlaywrightWorkerArgs,
PlaywrightWorkerOptions, PlaywrightWorkerOptions,
Locator, Locator,
} from '@playwright/test'; } from '@playwright/test';
import type { InlineConfig } from 'vite';
export type PlaywrightTestConfig = Omit<BasePlaywrightTestConfig, 'use'> & {
use: BasePlaywrightTestConfig['use'] & { vitePort?: number, viteConfig?: InlineConfig }
};
interface ComponentFixtures { interface ComponentFixtures {
mount(component: any, options?: { mount(component: any, options?: {
@ -35,4 +41,4 @@ export const test: TestType<
PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures, PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures,
PlaywrightWorkerArgs & PlaywrightWorkerOptions>; PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
export { expect } from '@playwright/test'; export { expect, devices } from '@playwright/test';

View file

@ -14,13 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
const { test: baseTest, expect, _addRunnerPlugin } = require('@playwright/test'); const { test: baseTest, expect, devices, _addRunnerPlugin } = require('@playwright/test');
const { mount } = require('@playwright/test/lib/mount'); const { mount } = require('@playwright/test/lib/mount');
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
_addRunnerPlugin(createPlugin( _addRunnerPlugin(() => {
'@playwright/experimental-ct-svelte/register', // Only fetch upon request to avoid resolution in workers.
() => require('@sveltejs/vite-plugin-svelte').svelte())); const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
'@playwright/experimental-ct-svelte/register',
() => require('@sveltejs/vite-plugin-svelte').svelte());
});
const test = baseTest.extend({ const test = baseTest.extend({
_workerPage: [async ({ browser }, use) => { _workerPage: [async ({ browser }, use) => {
@ -45,4 +48,4 @@ const test = baseTest.extend({
}, },
}); });
module.exports = { test, expect }; module.exports = { test, expect, devices };

View file

@ -14,7 +14,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"exports": { "exports": {
"./register": "./register.mjs", "./register": "./register.mjs",
"./test": "./test.js" ".": "./index.js"
}, },
"dependencies": { "dependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",

View file

@ -4,7 +4,5 @@
!LICENSE !LICENSE
!register.d.ts !register.d.ts
!register.mjs !register.mjs
!test.d.ts !index.d.ts
!test.js !index.js
!vitePlugin.d.ts
!vitePlugin.js

View file

@ -17,11 +17,17 @@
import type { import type {
TestType, TestType,
PlaywrightTestArgs, PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions, PlaywrightTestOptions,
PlaywrightWorkerArgs, PlaywrightWorkerArgs,
PlaywrightWorkerOptions, PlaywrightWorkerOptions,
Locator, Locator,
} from '@playwright/test'; } from '@playwright/test';
import type { InlineConfig } from 'vite';
export type PlaywrightTestConfig = Omit<BasePlaywrightTestConfig, 'use'> & {
use: BasePlaywrightTestConfig['use'] & { vitePort?: number, viteConfig?: InlineConfig }
};
interface ComponentFixtures { interface ComponentFixtures {
mount(component: JSX.Element): Promise<Locator>; mount(component: JSX.Element): Promise<Locator>;
@ -36,4 +42,4 @@ export const test: TestType<
PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures, PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures,
PlaywrightWorkerArgs & PlaywrightWorkerOptions>; PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
export { expect } from '@playwright/test'; export { expect, devices } from '@playwright/test';

View file

@ -14,13 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
const { test: baseTest, expect, _addRunnerPlugin } = require('@playwright/test'); const { test: baseTest, expect, devices, _addRunnerPlugin } = require('@playwright/test');
const { mount } = require('@playwright/test/lib/mount'); const { mount } = require('@playwright/test/lib/mount');
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
_addRunnerPlugin(createPlugin( _addRunnerPlugin(() => {
'@playwright/experimental-ct-vue/register', // Only fetch upon request to avoid resolution in workers.
() => require('@vitejs/plugin-vue')())); const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
'@playwright/experimental-ct-vue/register',
() => require('@vitejs/plugin-vue')());
});
const test = baseTest.extend({ const test = baseTest.extend({
_workerPage: [async ({ browser }, use) => { _workerPage: [async ({ browser }, use) => {
@ -45,4 +48,4 @@ const test = baseTest.extend({
}, },
}); });
module.exports = { test, expect }; module.exports = { test, expect, devices };

View file

@ -14,7 +14,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"exports": { "exports": {
"./register": "./register.mjs", "./register": "./register.mjs",
"./test": "./test.js" ".": "./index.js"
}, },
"dependencies": { "dependencies": {
"@vitejs/plugin-vue": "^2.3.1", "@vitejs/plugin-vue": "^2.3.1",

View file

@ -4,4 +4,3 @@ matchers/
reporters/ reporters/
third_party/ third_party/
plugins/ plugins/
plugins/webServerPlugin.ts

View file

@ -33,8 +33,10 @@ export const setRunnerToAddPluginsTo = (runner: Runner) => {
runnerInstanceToAddPluginsTo = runner; runnerInstanceToAddPluginsTo = runner;
}; };
export const addRunnerPlugin = (plugin: TestRunnerPlugin) => { export const addRunnerPlugin = (plugin: TestRunnerPlugin | (() => TestRunnerPlugin)) => {
// Only present in runner, absent in worker. // Only present in runner, absent in worker.
if (runnerInstanceToAddPluginsTo) if (runnerInstanceToAddPluginsTo) {
plugin = typeof plugin === 'function' ? plugin() : plugin;
runnerInstanceToAddPluginsTo.addPlugin(plugin); runnerInstanceToAddPluginsTo.addPlugin(plugin);
}
}; };

View file

@ -34,9 +34,9 @@ export function createPlugin(
name: 'playwright-vite-plugin', name: 'playwright-vite-plugin',
setup: async (config: FullConfig, configDirectory: string, suite: Suite) => { setup: async (config: FullConfig, configDirectory: string, suite: Suite) => {
// TODO: declare and pick these from the config. const use = config.projects[0].use as any;
const viteConfig: InlineConfig = {}; const viteConfig: InlineConfig = use.viteConfig || {};
const port = 3100; const port = use.vitePort || 3100;
configDir = configDirectory; configDir = configDirectory;

View file

@ -14,19 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
import type { PlaywrightTestConfig } from '@playwright/test'; import type { PlaywrightTestConfig } from '@playwright/experimental-ct-react';
import { devices } from '@playwright/test'; import { devices } from '@playwright/experimental-ct-react';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',
forbidOnly: !!process.env.CI, forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0, retries: process.env.CI ? 2 : 0,
reporter: process.env.CI ? [ reporter: 'html',
['html', { open: 'never' }],
] : [
['html', { open: 'on-failure' }]
],
use: { use: {
vitePort: 3102,
trace: 'on-first-retry', trace: 'on-first-retry',
}, },
projects: [ projects: [

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { expect, test } from '@playwright/experimental-ct-react/test'; import { expect, test } from '@playwright/experimental-ct-react';
import { Expandable } from './expandable'; import { Expandable } from './expandable';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { expect, test } from '@playwright/experimental-ct-react/test'; import { expect, test } from '@playwright/experimental-ct-react';
import { Source } from './source'; import { Source } from './source';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -15,7 +15,7 @@
*/ */
import React from 'react'; import React from 'react';
import { expect, test } from '@playwright/experimental-ct-react/test'; import { expect, test } from '@playwright/experimental-ct-react';
import { SplitView } from './splitView'; import { SplitView } from './splitView';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { PlaywrightTestConfig, devices } from '@playwright/test'; import { type PlaywrightTestConfig, devices } from '@playwright/experimental-ct-react';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-react/test'; import { test, expect } from '@playwright/experimental-ct-react';
import App from './App'; import App from './App';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { PlaywrightTestConfig, devices } from '@playwright/test'; import { type PlaywrightTestConfig, devices } from '@playwright/experimental-ct-react';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-react/test'; import { test, expect } from '@playwright/experimental-ct-react';
import App from './App'; import App from './App';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import type { PlaywrightTestConfig } from '@playwright/test'; import type { PlaywrightTestConfig } from '@playwright/experimental-ct-svelte';
import { devices } from '@playwright/test'; import { devices } from '@playwright/test';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from '@playwright/experimental-ct-svelte/test'; import { test, expect } from '@playwright/experimental-ct-svelte';
import Counter from './Counter.svelte'; import Counter from './Counter.svelte';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import type { PlaywrightTestConfig } from '@playwright/test'; import type { PlaywrightTestConfig } from '@playwright/experimental-ct-svelte';
import { devices } from '@playwright/test'; import { devices } from '@playwright/test';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from '@playwright/experimental-ct-svelte/test'; import { test, expect } from '@playwright/experimental-ct-svelte';
import Counter from './Counter.svelte'; import Counter from './Counter.svelte';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import type { PlaywrightTestConfig } from '@playwright/test'; import type { PlaywrightTestConfig } from '@playwright/experimental-ct-svelte';
import { devices } from '@playwright/test'; import { devices } from '@playwright/test';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from '@playwright/experimental-ct-svelte/test'; import { test, expect } from '@playwright/experimental-ct-svelte';
import App from './App.svelte'; import App from './App.svelte';
test.use({ viewport: { width: 500, height: 500 } }); test.use({ viewport: { width: 500, height: 500 } });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { PlaywrightTestConfig, devices } from '@playwright/test'; import { type PlaywrightTestConfig, devices } from '@playwright/experimental-ct-vue';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import Button from './components/Button.vue' import Button from './components/Button.vue'
import DefaultSlot from './components/DefaultSlot.vue' import DefaultSlot from './components/DefaultSlot.vue'
import NamedSlots from './components/NamedSlots.vue' import NamedSlots from './components/NamedSlots.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import Button from './components/Button.vue' import Button from './components/Button.vue'
import DefaultSlot from './components/DefaultSlot.vue' import DefaultSlot from './components/DefaultSlot.vue'

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { PlaywrightTestConfig, devices } from '@playwright/test'; import { type PlaywrightTestConfig, devices } from '@playwright/experimental-ct-vue';
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
testDir: 'src', testDir: 'src',

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import Button from './components/Button.vue' import Button from './components/Button.vue'
import DefaultSlot from './components/DefaultSlot.vue' import DefaultSlot from './components/DefaultSlot.vue'
import NamedSlots from './components/NamedSlots.vue' import NamedSlots from './components/NamedSlots.vue'

View file

@ -1,4 +1,4 @@
import { test, expect } from '@playwright/experimental-ct-vue/test' import { test, expect } from '@playwright/experimental-ct-vue'
import Button from './components/Button.vue' import Button from './components/Button.vue'
import DefaultSlot from './components/DefaultSlot.vue' import DefaultSlot from './components/DefaultSlot.vue'