kolodny / safetest

MIT License
1.31k stars 31 forks source link

Module not found when using Webpack #20

Closed Anoerak closed 2 months ago

Anoerak commented 3 months ago

Hi,

I want to see if safetest can be integrated within our system but I still get this error:

WARNING in ./node_modules/safetest/lib/setup.js 14:35-74
Critical dependency: the request of a dependency is an expression
 @ ./setup-safetest.tsx 1:0-39 3:0-5

ERROR in ./node_modules/safetest/lib/setup.js 4:11-23
Module not found: Error: Can\'t resolve '.' in 'MY_PATH_TO_SAFETEST_LIB_/..'

ERROR in ./node_modules/safetest/lib/setup.js 5:17-36
Module not found: Error: Can\'t resolve './docker' in 'MY_PATH_TO_SAFETEST_LIB_/..'

ERROR in ./node_modules/safetest/lib/setup.js 6:16-34
Module not found: Error: Can\'t resolve './state' in 'MY_PATH_TO_SAFETEST_LIB_/..'

ERROR in ./node_modules/safetest/lib/setup.js 8:26-54
Module not found: Error: Can\'t resolve './redirect-server' in 'MY_PATH_TO_SAFETEST_LIB_/..'

ERROR in ./node_modules/safetest/lib/setup.js 9:23-48
Module not found: Error: Can\'t resolve './safe-require' in 'MY_PATH_TO_SAFETEST_LIB_/..'

ERROR in ./node_modules/safetest/lib/setup.js 10:20-42
Module not found: Error: Can\'t resolve './artifacts' in 'MY_PATH_TO_SAFETEST_LIB_/..'

And here is my setup-safetest.ts:

const { setup } = require("safetest/setup");

setup({
    bootstrappedAt: require.resolve("./src/index.tsx"),
    ciOptions: {
        usingArtifactsDir: "artifacts",
    },
});

And finally my webpack.config for the safetest command:

const path = require("path");

module.exports = {
    mode: "development",
    entry: path.resolve(__dirname, "./setup-safetest.tsx"),
    output: {
        filename: "bundle.js",
        path: path.resolve(__dirname, "./src/tests/report/"),
    },
    resolve: {
        extensions: ['.tsx'],
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                include: [
                    path.resolve(__dirname, "src/tests/"),
                ],
                exclude: /node_modules/,
                use: [
                    {
                        loader: "babel-loader",
                        options: {
                            presets: [
                                "@babel/preset-env",
                                "@babel/preset-react",
                                "@babel/preset-typescript",
                            ],
                        },
                    },
                ],

            },
        ],
    },
};

Any help is very welcome :)

kolodny commented 3 months ago

setup-safetest is only meant to be used by Jest or Vitest, it's not meant to be bundled to the browser. Try removing it from the webpack config and add it to either package.json for the jest command or the vite config. See the docs for how to do that

kolodny commented 2 months ago

Closing for now, feel free to reopen if you still have an issue with this.