【发布时间】:2020-11-20 07:27:35
【问题描述】:
当作业在 Azure DevOps yarn test:unit 上运行时,会多次发生以下错误。这不会阻止测试通过。该项目运行vue 和jest 进行测试。在本地运行时,不会出现错误。
jest.config.js
const Vue = require('vue');
const Vuetify = require('vuetify');
Vue.use(Vuetify);
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
collectCoverage: false,
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/registerServiceWorker.js',
'!src/helpers.js',
'!src/constants/**',
'!src/mixins/**',
'!src/plugins/**',
'!src/router/**',
'!src/test/**',
'!src/main.js', // No need to cover bootstrap file
],
transform: {
'vee-validate/dist/rules': 'babel-jest',
},
transformIgnorePatterns: [
'<roodDir>/node_modules/(?!vee-validate/dist/rules)',
],
testEnvironmentOptions: {
// Allow test environment to fire onload event
// See https://github.com/jsdom/jsdom/issues/1816#issuecomment-355188615
resources: 'usable',
},
};
axios.js
let baseURL = '';
switch (process.env.NODE_ENV) {
case 'development': {
baseURL = 'https://localhost:44359/api/v1';
break;
}
case 'production': {
baseURL = 'webapi/api/v1';
break;
}
case 'docker': {
const port = process.env.VUE_APP_WebAPI_PORT;
const path = process.env.VUE_APP_WebAPI_Path;
const version = process.env.VUE_APP_WebAPI_Version;
const url = new URL(window.location.origin);
url.port = port;
baseURL = `${url.origin.toString()}/${path}/${version}`;
break;
}
default: baseURL = 'webapi/api/v1';
}
/* eslint-disable import/prefer-default-export */
export const http = axios.create({
baseURL,
withCredentials: true,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
paramsSerializer: (params) => {
Object.keys(params).forEach((key) => {
if (_isArray(params[key]) && !params[key].length) {
delete params[key];
}
});
return qs.stringify(params, { arrayFormat: 'repeat' });
},
});
错误
错误:错误:连接 ECONNREFUSED 127.0.0.1:80 在 Object.dispatchError (/home/vsts/work/1/s/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:54:19) 在请求。 (/home/vsts/work/1/s/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:675:20) 在 Request.emit (events.js:327:22) 在 Request.onRequestError (/home/vsts/work/1/s/node_modules/request/request.js:877:8) 在 ClientRequest.emit (events.js:315:20) 在 Socket.socketErrorListener (_http_client.js:426:9) 在 Socket.emit (events.js:315:20) 在 emitErrorNT (internal/streams/destroy.js:92:8) 在 emitErrorAndCloseNT (internal/streams/destroy.js:60:3) 在 processTicksAndRejections (internal/process/task_queues.js:84:21) 未定义 console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
欢迎任何帮助
【问题讨论】:
-
你能展示你的管道吗?您如何构建和测试这个项目?
-
我附加了正在运行的作业。该项目使用
yarn:build命令构建,该命令基本上运行vue-cli-service build,并使用vue-cli-service test:unit进行测试
标签: vue.js azure-devops jestjs