我遇到了剧作家编码测试自动化的问题。运行测试时,test.spec.ts出现如下错误:
错误:找不到模块“@common/common” 代码:“MODULE_NOT_FOUND”
如何解决这个问题呢?
下面有代码
测试规范.ts
import { chromium, ChromiumBrowser, Page } from "playwright";
import { test, expect, PlaywrightTestConfig } from "@playwright/test";
import Common from "@common/common";
test.beforeAll(async ({ page }) => {
});
test.describe('Go test', () => {
test('Test1', async ({ page }) => {
console.log("1111111111");
});
})
包.json
{
"name": "type-sanity",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"test": "npx playwright test"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/randomstring": "^1.1.7",
"playwright": "^1.14.0",
"randomstring": "^1.2.1",
"typescript": "^4.3.5"
},
"devDependencies": {
"@playwright/test": "^1.14.0",
"@types/node": "latest",
"ts-node": "^10.1.0",
"tsconfig-paths": "^3.10.1",
"typescript-module-alias": "^1.0.2"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"outDir": "./dist",
"baseUrl": ".",
"types": [],
"paths": {
"@config/*": [
"tests/config/*"
],
"@common/*": [
"src/common/*"
],
}
},
"exclude": [
"node_modules"
]
}