webpack如何用笑话来运行打字稿测试

时间:2019-12-15 09:12:23

标签: typescript webpack jestjs

我有一个与Webpack集成的打字稿项目。我需要添加测试文件,并需要产生覆盖率。但是我不知道如何在纯ts文件上使用webpack运行测试。有人帮我吗?

这是我的package.json文件:

{
  "name": "js-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --mode development --hot",
    "build": "webpack --mode production"
  },
  "author": "Arif",
  "license": "ISC",
  "devDependencies": {
    "@types/enzyme": "^3.10.4",
    "@types/jest": "^24.0.23",
    "css-loader": "^3.3.2",
    "html-webpack-plugin": "^3.2.0",
    "jest": "^24.9.0",
    "md5": "^2.2.1",
    "script-ext-html-webpack-plugin": "^2.1.4",
    "style-loader": "^1.0.1",
    "ts-jest": "^24.2.0",
    "ts-loader": "^6.2.1",
    "typescript": "^3.7.3",
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.9.0"
  },
  "dependencies": {}
}

这是我的webpack.config文件:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');


module.exports = {
    entry: './src/index.ts',
    resolve: {
        extensions: ['.ts', '.js',]
    },
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'bundle.min.js'
    },
    module: {
        rules: [
            {
                test: /\.ts?$/i,
                loader: 'ts-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
        ]
    },
    resolve: {
        extensions: [".ts", ".js"]
    },
    plugins: [
        new HtmlWebpackPlugin({
          template: './src/index.html',
          async: ['bundle.min.js']
        }),
        new ScriptExtHtmlWebpackPlugin({
            defer: 'bundle.min.js',
            defaultAttribute: 'defer'
        })
      ]
};

请帮助我。预先感谢

0 个答案:

没有答案