-
Notifications
You must be signed in to change notification settings - Fork 26.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to test middleware with cucumber-js #35089
Comments
First, all credits for this issue go to davidrhoderick who reported the same issue #32848 when running tests with jest. The problem described in the original issue is the same that occurs with
Let's get started; If you use
SolutionHere's how to make it work: Configure cucumber// cucumber.js
const defaults = [
'--require cucumber.setup.js',
'--require cucumber/runner.js',
// Test files
'--require __tests__/**/**/*.spec.ts',
'--require __tests__/**/**/*.spec.tsx',
'--require src/**/**__tests__/**/**/*.spec.ts',
'--require src/**/**__tests__/**/**/*.spec.tsx',
// Features
'**/**__tests__/**/**features/**/*.feature',
// Additional args
'--publish-quiet',
].join(' ');
module.exports = {
ci: `
--world-parameters '{"ci": "true"}'
${defaults}
--exit
`,
default: `
${defaults}
`,
}; // cucumber.setup.js
// This prevents `Request is not defined` error
require("isomorphic-fetch");
const ignoredModules = ["next/server"].join("|");
require("ts-node").register({
transpileOnly: true,
ignore: [`node_modules/(?!${ignoredModules})`],
// Do not add custom tsconfig here, it is managed under root tsconfig.json
});
require("tsconfig-paths").register();
// If you're testing components
require("jsdom-global/register"); Configure TypeScript// tsconfig.json
{
"ts-node": {
"compilerOptions": {
// ...
"module": "commonjs",
"jsx": "react-jsx", // override jsx for ts-node
"allowJs": true
// ...
}
},
"compilerOptions": {
// ...
"jsx": "preserve" // required by NextJS: will be automatically updated if you use another value
//...
},
// ...
} RunThen you can run cucumber yarn run cucumber-js # will automatically use your cucumber.js file for setup |
Closing as the proposed setup should work, and the issue is not with Next.js. Another solution would be to make the test environment ESM compatible, although not being familiar with Cucumber.js I'm not sure it's possible. #32848 relies on |
Yes you're right, it's not in next scope. |
Thanks for sharing. FWIW, we are already working on the |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
N/A
How are you deploying your application? (if relevant)
N/A
Describe the Bug
When trying to test
_middleware.ts
with Cucumber (https://github.com/cucumber/cucumber-js),I'm unable to import { NextResponse } from 'next/server' without throwing an error SyntaxError: Unexpected token 'export' because next/server uses export { NextRequest } in line 1.
Expected Behavior
I would like to be able to test my
_middleware.ts
authentication methodology.To Reproduce
_middleware.ts
The text was updated successfully, but these errors were encountered: