我正在创建 next.js 应用程序,并在页面目录中进行测试。为此,我已将配置添加到 next.config.js
const { i18n } = require('./next-i18next.config');
const nextConfig = {
reactStrictMode: true,
pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
styledComponents: true,
i18n,
};
module.exports = nextConfig;
Run Code Online (Sandbox Code Playgroud)
我的所有页面都有一个扩展名 page.tsx。例如 Home.page.tsx。我的测试文件命名如下:Home.spec.tsx。
问题是,我的测试文件仍然包含在构建中。我确实将它们排除在我的 tsconfig 文件中
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"types": ["node", "jest", "@testing-library/jest-dom"]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "**/*.spec.ts", "**/*.spec.tsx"] …Run Code Online (Sandbox Code Playgroud)