# karma **Repository Path**: peppa-qiu/karma ## Basic Information - **Project Name**: karma - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-20 - **Last Updated**: 2024-10-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 1. `npm init` 2. `npm install karma jasmine-core karma-jasmine karma-chrome-launcher` 3. `karma init` > 配置测试文件所在位置 ![](./images/test-file-location.png) ![](./images/test-file-config.png) #### 用于 ES6 语法转换成 ES5 语法 - `npm install --save-dev @babel/core @babel/preset-env babel-loader karma-babel-preprocessor` - 根目录创建 `.babelrc` 文件 ```json { "presets": ["@babel/preset-env"] } ``` - `npm install --save-dev webpack webpack-cli karma-webpack` - 根目录创建 `webpack.config.js` 文件 ```js const path = require('path'); module.exports = { mode: 'development', entry: './src/index.js', // 你的入口文件 output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } } ] } }; ``` - 修改 `karma.conf.js` 文件 ```text // preprocess matching files before serving them to the browser // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor // 在提供给浏览器之前预处理匹配的文件 preprocessors: { 'src/**/*.js': ['webpack'], 'test/**/*.spec.js': ['webpack'] }, // Webpack 配置 webpack: require('./webpack.config') ```