modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.21k stars 286 forks source link

[@web/test-runner]: does not accept rollup plugins #1787

Open YonatanKra opened 2 years ago

YonatanKra commented 2 years ago

Hi, In the documentation I see that the test runner is supposed to accept rollup plugins: https://modern-web.dev/docs/dev-server/plugins/rollup/ When I try it, it doesn't work. Here's my code:

import { PlaywrightTestConfig, devices } from '@playwright/test';
import {fromRollup} from "@web/dev-server-rollup";
import typescript from "@rollup/plugin-typescript";

const specTypescriptConfig = {tsconfig: './config/typescript/tsconfig.spec.json'};

interface PlaywrightTestConfigWithRegression extends PlaywrightTestConfig {
    plugins: any[];
}

const tsPlugin = fromRollup(typescript);

const config: PlaywrightTestConfigWithRegression = {
    testMatch: 'src/**/*.test.ts',
    projects: [
        {
            name: 'Chrome Stable',
            use: {
                browserName: 'chromium',
                channel: 'chrome',
            },
        }
    ],
    plugins: [
        tsPlugin(specTypescriptConfig)
    ],
};
export default config;

Inside my test I import the source code (which is typescript). It doesn't work. I get an error as if TS is not running on my source code (which has decorators for instance).

Is it a bug or is something's wrong with my usage?

Westbrook commented 2 years ago

You shouldn't be importing *.ts files in your code. If you update those to *.js you should be fine.

Separately, you might want to look at the esbuild plugin for a more common path towards typescript support with WTR: https://modern-web.dev/docs/dev-server/plugins/esbuild/