我有一个量角器测试可以做到这一点:
it('Test', async () => {
throw new Error()
}
当此错误时,它会输出以下内容:
✗ Test
- Failed: Error
at callWhenIdle (.../node_modules/jasminewd2/index.js:62:5)
at .../node_modules/jasminewd2/index.js:127:13
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) (node:43369) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: EPIPE write EPIPE
如何获得有用的堆栈跟踪,说明错误是在测试的适当行引发的?
这是我的量角器配置文件:
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const {SpecReporter} = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: '../build/test-results/e2e/screenshots',
filename: 'e2e-report.html',
reportOnlyFailedSpecs: true,
captureOnlyFailedSpecs: true,
showQuickLinks: true,
reportFailedUrl: true,
inlineImages: true
});
exports.config = {
SELENIUM_PROMISE_MANAGER: false,
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ["--headless", "--disable-gpu", "--window-size=1920,1080"]
}
},
directConnect: true,
baseUrl: 'http://localhost:4201/',
params: {},
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function () {
}
},
beforeLaunch: function () {
return new Promise(function (resolve) {
process.on('uncaughtException', function () {
reporter.jasmineDone();
reporter.afterLaunch();
});
reporter.beforeLaunch(resolve);
});
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});
jasmine.getEnv().addReporter(reporter);
jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
console.log("==========> Target report configuration", browser.params.products[process.env.TARGET_REPORT_SKU]);
},
afterLaunch: function (exitCode) {
return new Promise(function (resolve) {
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
对于它的价值,我正在通过 gradle 命令运行测试。
我尝试创建一个新的量角器应用程序,发现它有同样的问题。因此,我在他们的 github 上创建了一个问题:https ://github.com/angular/protractor/issues/4975