From 74d0344701e67fe20ed71f1ca4a9d2d4cbf42b68 Mon Sep 17 00:00:00 2001 From: Georgiy Abbasov Date: Mon, 13 Feb 2017 13:52:56 +0300 Subject: [PATCH] Changed babel options to avoid extra lines in report (closes #1226) --- .../es-next/compile-client-function.js | 2 +- src/compiler/es-next/index.js | 10 +--- test/server/compiler-test.js | 54 ++++++++++++++----- .../typeof/expected-node10.js | 7 ++- .../test-suites/regression-gh-1226/helper.js | 3 ++ .../regression-gh-1226/testfile.js | 8 +++ 6 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 test/server/data/test-suites/regression-gh-1226/helper.js create mode 100644 test/server/data/test-suites/regression-gh-1226/testfile.js diff --git a/src/compiler/es-next/compile-client-function.js b/src/compiler/es-next/compile-client-function.js index 7dd232ad236..d26637064f8 100644 --- a/src/compiler/es-next/compile-client-function.js +++ b/src/compiler/es-next/compile-client-function.js @@ -10,7 +10,7 @@ const ANONYMOUS_FN_RE = /^function\*?\s*\(/; const USE_STRICT_RE = /^('|")use strict('|");?/; const TRAILING_SEMICOLON_RE = /;\s*$/; const REGENERATOR_FOOTPRINTS_RE = /(_index\d+\.default|_regenerator\d+\.default|regeneratorRuntime)\.wrap\(function _callee\$\(_context\)/; -const ASYNC_TO_GENERATOR_OUTPUT_CODE = asyncToGenerator(noop).toString().replace(/\n\s*/g, ''); +const ASYNC_TO_GENERATOR_OUTPUT_CODE = asyncToGenerator(noop).toString(); var babelArtifactPolyfills = { 'Promise': { diff --git a/src/compiler/es-next/index.js b/src/compiler/es-next/index.js index 4dc08aa35e2..fd3ddbb8fe2 100644 --- a/src/compiler/es-next/index.js +++ b/src/compiler/es-next/index.js @@ -36,14 +36,8 @@ export default class ESNextCompiler { // NOTE: passPrePreset and complex presets is a workaround for https://github.com/babel/babel/issues/2877 // Fixes https://github.com/DevExpress/testcafe/issues/969 return { - passPerPreset: true, - presets: [ - { plugins: transformRuntime }, - { - passPerPreset: false, - presets: [presetStage2, presetEnv] - } - ], + presets: [presetStage2, presetEnv], + plugins: [transformRuntime], filename: filename, sourceMaps: true, retainLines: true, diff --git a/test/server/compiler-test.js b/test/server/compiler-test.js index f05137fc50f..cb6ba70f45b 100644 --- a/test/server/compiler-test.js +++ b/test/server/compiler-test.js @@ -1,16 +1,17 @@ -var expect = require('chai').expect; -var resolve = require('path').resolve; -var sep = require('path').sep; -var readFile = require('fs').readFileSync; -var Promise = require('pinkie'); -var stackParser = require('error-stack-parser'); -var stripAnsi = require('strip-ansi'); -var sortBy = require('lodash').sortBy; -var renderers = require('callsite-record').renderers; -var ERR_TYPE = require('../../lib/errors/test-run/type'); -var Compiler = require('../../lib/compiler'); -var commonAPI = require('../../lib/api/common'); -var NODE_VER = require('../../lib/utils/node-version'); +var expect = require('chai').expect; +var resolve = require('path').resolve; +var sep = require('path').sep; +var readFile = require('fs').readFileSync; +var Promise = require('pinkie'); +var stackParser = require('error-stack-parser'); +var stripAnsi = require('strip-ansi'); +var sortBy = require('lodash').sortBy; +var renderers = require('callsite-record').renderers; +var ERR_TYPE = require('../../lib/errors/test-run/type'); +var Compiler = require('../../lib/compiler'); +var commonAPI = require('../../lib/api/common'); +var NODE_VER = require('../../lib/utils/node-version'); +var createStackFilter = require('../../lib/errors/create-stack-filter.js'); describe('Compiler', function () { var testRunMock = { id: 'yo' }; @@ -1239,5 +1240,32 @@ describe('Compiler', function () { expect(callsite).contains(' > 19 | .method1()\n'); }); }); + + it('Incorrect callsite stack in error report if "import" is used (GH-1226)', function () { + this.timeout(5000); + + var src = 'test/server/data/test-suites/regression-gh-1226/testfile.js'; + var compiler = new Compiler([src]); + + return compiler + .getTests() + .then(function (tests) { + var test = tests[0]; + + return test.fn(testRunMock); + }) + .then(function () { + throw 'Promise rejection expected'; + }) + .catch(function (err) { + var stackTraceLimit = 200; + var stack = err.callsite.stackFrames.filter(createStackFilter(stackTraceLimit)); + + expect(stack.length).eql(3); + expect(stack[0].source).to.have.string('helper.js'); + expect(stack[1].source).to.have.string('helper.js'); + expect(stack[2].source).to.have.string('testfile.js'); + }); + }); }); }); diff --git a/test/server/data/client-fn-compilation/typeof/expected-node10.js b/test/server/data/client-fn-compilation/typeof/expected-node10.js index 6c19773c049..184641e3258 100644 --- a/test/server/data/client-fn-compilation/typeof/expected-node10.js +++ b/test/server/data/client-fn-compilation/typeof/expected-node10.js @@ -1,5 +1,10 @@ (function () { + var_typeof3 = { + default: function (obj) { + return typeof obj; + } + }; return (function () { - return typeof someObj === "undefined" ? "undefined" : _typeof(someObj); + return typeof someObj === "undefined" ? "undefined" : (0, _typeof3.default)(someObj); }); })(); diff --git a/test/server/data/test-suites/regression-gh-1226/helper.js b/test/server/data/test-suites/regression-gh-1226/helper.js new file mode 100644 index 00000000000..bafbf9c567f --- /dev/null +++ b/test/server/data/test-suites/regression-gh-1226/helper.js @@ -0,0 +1,3 @@ +export default async function (t) { + throw new Error(); +} diff --git a/test/server/data/test-suites/regression-gh-1226/testfile.js b/test/server/data/test-suites/regression-gh-1226/testfile.js new file mode 100644 index 00000000000..f1cc82e104d --- /dev/null +++ b/test/server/data/test-suites/regression-gh-1226/testfile.js @@ -0,0 +1,8 @@ +import help from './helper.js'; + +fixture `Test` + .page `http://example.com`; + +test('test', async t => { + await help(t); +});