modernweb-dev / web

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

Snapshot testing is not working #2127

Open alenaksu opened 1 year ago

alenaksu commented 1 year ago

As in the title, snapshot testing is not working, it throws the following error

Failed to fetch dynamically imported module: data:text/package.json?wds-javascript;charset=utf-8,...

Test example:

it('should not throw',() => {
    const el = await fixture(
        html`<my-custom-element></my-custom-element>`
    );
    expect(el).shadowDom.to.equalSnapshot();
});

Digging a little bit, It seems that the framework tries to dynamically import the snapshot here, but that file is subject to various transformations, especially by transformModuleImportsPlugin, at the end the import specifier changes from data:text/javascript... to data:text/package.json?wds-javascript....

I'm not sure though if there is something wrong in my configuration:

export default {
    files: ['src/**/*.spec.ts'],
    plugins: [
        esbuildPlugin({ ts: true }),
        importMapsPlugin({
            inject: {
                exclude: ['node_modules'],
                importMap: {
                    imports: {
                        '/src/lib/api.ts': '/__mocks__/lib/api.ts',
                    },
                },
            },
        }),
    ],
    nodeResolve: true
};
mauricioaraldi commented 10 months ago

Also having this problem. Any updates here?