From cec19868719576160d2d360d8d240aca173590d9 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Mon, 10 Jul 2017 09:11:24 +0100 Subject: [PATCH 1/2] test: fix tests on CI --- appveyor.yml | 1 + test/__snapshots__/index.test.js.snap | 75 ++------------------------- test/helpers.js | 4 -- test/index.test.js | 5 +- test/utils/loader.js | 11 ++++ test/{ => utils}/webpack.js | 11 ++-- 6 files changed, 27 insertions(+), 80 deletions(-) delete mode 100644 test/helpers.js create mode 100644 test/utils/loader.js rename test/{ => utils}/webpack.js (70%) diff --git a/appveyor.yml b/appveyor.yml index aa4f18a..bf3f13c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,6 +19,7 @@ matrix: fast_finish: true install: - ps: Install-Product node $env:nodejs_version x64 + - cmd: npm i -g npm@latest - npm install before_test: - cmd: npm install webpack@%webpack_version% diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 9be6247..098e78e 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1,88 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`disabled sourcemaps 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///webpack/bootstrap 1ae028e11f9e6449a2dd\\",\\"webpack:///./test/fixtures/basic.js\\"],\\"names\\":[],\\"mappings\\":\\";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;AC7DA,8BAA8B,uNAAuN,2GAA2G,KAAK,OAAO,gBAAgB,MAAM,kBAAkB,MAAM,OAAO,gBAAgB,MAAM,kBAAkB,MAAM,OAAO,gBAAgB,MAAM,mBAAmB,QAAQ,KAAK,2BAA2B,OAAO,gBAAgB,MAAM,iBAAiB,MAAM,OAAO,gBAAgB,MAAM,iBAAiB,QAAQ,MAAM,2BAA2B,OAAO,gBAAgB,MAAM,iBAAiB,MAAM,OAAO,gBAAgB,MAAM,iBAAiB,SAAS,aAAa,IAAI,kBAAkB,IAAI,YAAY,KAAK,4DAA4D,sCAAsC,EAAE,+CAA+C,uBAAuB,uBAAuB,oCAAoC,GAAG,sBAAsB,yBAAyB,MAAM,sBAAsB,sBAAsB,cAAc,MAAM,sBAAsB,sBAAsB,qB\\",\\"file\\":\\"main.js\\",\\"sourcesContent\\":[\\" \\\\t// The module cache\\\\n \\\\tvar installedModules = {};\\\\n\\\\n \\\\t// The require function\\\\n \\\\tfunction __webpack_require__(moduleId) {\\\\n\\\\n \\\\t\\\\t// Check if module is in cache\\\\n \\\\t\\\\tif(installedModules[moduleId]) {\\\\n \\\\t\\\\t\\\\treturn installedModules[moduleId].exports;\\\\n \\\\t\\\\t}\\\\n \\\\t\\\\t// Create a new module (and put it into the cache)\\\\n \\\\t\\\\tvar module = installedModules[moduleId] = {\\\\n \\\\t\\\\t\\\\ti: moduleId,\\\\n \\\\t\\\\t\\\\tl: false,\\\\n \\\\t\\\\t\\\\texports: {}\\\\n \\\\t\\\\t};\\\\n\\\\n \\\\t\\\\t// Execute the module function\\\\n \\\\t\\\\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\\\\n\\\\n \\\\t\\\\t// Flag the module as loaded\\\\n \\\\t\\\\tmodule.l = true;\\\\n\\\\n \\\\t\\\\t// Return the exports of the module\\\\n \\\\t\\\\treturn module.exports;\\\\n \\\\t}\\\\n\\\\n\\\\n \\\\t// expose the modules object (__webpack_modules__)\\\\n \\\\t__webpack_require__.m = modules;\\\\n\\\\n \\\\t// expose the module cache\\\\n \\\\t__webpack_require__.c = installedModules;\\\\n\\\\n \\\\t// define getter function for harmony exports\\\\n \\\\t__webpack_require__.d = function(exports, name, getter) {\\\\n \\\\t\\\\tif(!__webpack_require__.o(exports, name)) {\\\\n \\\\t\\\\t\\\\tObject.defineProperty(exports, name, {\\\\n \\\\t\\\\t\\\\t\\\\tconfigurable: false,\\\\n \\\\t\\\\t\\\\t\\\\tenumerable: true,\\\\n \\\\t\\\\t\\\\t\\\\tget: getter\\\\n \\\\t\\\\t\\\\t});\\\\n \\\\t\\\\t}\\\\n \\\\t};\\\\n\\\\n \\\\t// getDefaultExport function for compatibility with non-harmony modules\\\\n \\\\t__webpack_require__.n = function(module) {\\\\n \\\\t\\\\tvar getter = module && module.__esModule ?\\\\n \\\\t\\\\t\\\\tfunction getDefault() { return module['default']; } :\\\\n \\\\t\\\\t\\\\tfunction getModuleExports() { return module; };\\\\n \\\\t\\\\t__webpack_require__.d(getter, 'a', getter);\\\\n \\\\t\\\\treturn getter;\\\\n \\\\t};\\\\n\\\\n \\\\t// Object.prototype.hasOwnProperty.call\\\\n \\\\t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\\\\n\\\\n \\\\t// __webpack_public_path__\\\\n \\\\t__webpack_require__.p = \\\\\\"\\\\\\";\\\\n\\\\n \\\\t// Load entry module and return exports\\\\n \\\\treturn __webpack_require__(__webpack_require__.s = 0);\\\\n\\\\n\\\\n\\\\n// WEBPACK FOOTER //\\\\n// webpack/bootstrap 1ae028e11f9e6449a2dd\\",\\"var cov_2obfoewtj5=function(){var path=\\\\\\"/Users/mattlewis/Code/open-source/istanbul-instrumenter-loader/test/fixtures/basic.js\\\\\\",hash=\\\\\\"d160bda36fc8432c2ffbb2cefc3c20475fdbdbec\\\\\\",global=new Function('return this')(),gcv=\\\\\\"__coverage__\\\\\\",coverageData={path:\\\\\\"/Users/mattlewis/Code/open-source/istanbul-instrumenter-loader/test/fixtures/basic.js\\\\\\",statementMap:{\\\\\\"0\\\\\\":{start:{line:1,column:0},end:{line:11,column:2}},\\\\\\"1\\\\\\":{start:{line:4,column:4},end:{line:4,column:18}},\\\\\\"2\\\\\\":{start:{line:8,column:4},end:{line:8,column:23}}},fnMap:{\\\\\\"0\\\\\\":{name:\\\\\\"(anonymous_0)\\\\\\",decl:{start:{line:3,column:2},end:{line:3,column:3}},loc:{start:{line:3,column:8},end:{line:5,column:3}},line:3},\\\\\\"1\\\\\\":{name:\\\\\\"(anonymous_1)\\\\\\",decl:{start:{line:7,column:2},end:{line:7,column:3}},loc:{start:{line:7,column:8},end:{line:9,column:3}},line:7}},branchMap:{},s:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0,\\\\\\"2\\\\\\":0},f:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0},b:{},_coverageSchema:\\\\\\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\\\\\"},coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}coverageData.hash=hash;return coverage[path]=coverageData;}();++cov_2obfoewtj5.s[0];module.exports=class Foo{bar(){++cov_2obfoewtj5.f[0];++cov_2obfoewtj5.s[1];return!!this;}baz(){++cov_2obfoewtj5.f[1];++cov_2obfoewtj5.s[2];return!this.bar();}};\\\\n\\\\n\\\\n//////////////////\\\\n// WEBPACK FOOTER\\\\n// ./test/fixtures/basic.js\\\\n// module id = 0\\\\n// module chunks = 0\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`disabled sourcemaps 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///./test/fixtures/basic.js\\"],\\"names\\":[],\\"mappings\\":\\";;;;AAAA,8BAA8B,oJAAoJ,wCAAwC,KAAK,OAAO,gBAAgB,MAAM,kBAAkB,MAAM,OAAO,gBAAgB,MAAM,kBAAkB,MAAM,OAAO,gBAAgB,MAAM,mBAAmB,QAAQ,KAAK,2BAA2B,OAAO,gBAAgB,MAAM,iBAAiB,MAAM,OAAO,gBAAgB,MAAM,iBAAiB,QAAQ,MAAM,2BAA2B,OAAO,gBAAgB,MAAM,iBAAiB,MAAM,OAAO,gBAAgB,MAAM,iBAAiB,SAAS,aAAa,IAAI,kBAAkB,IAAI,YAAY,KAAK,4DAA4D,sCAAsC,EAAE,+CAA+C,uBAAuB,uBAAuB,oCAAoC,GAAG,sBAAsB,yBAAyB,MAAM,sBAAsB,sBAAsB,cAAc,MAAM,sBAAsB,sBAAsB,qB\\",\\"file\\":\\"main.js\\",\\"sourcesContent\\":[\\"var cov_1v2zerd2hz=function(){var path=\\\\\\"/fixtures/basic.js\\\\\\",hash=\\\\\\"f67bc5731c59e70932ca6e13967f6329cc8682d3\\\\\\",global=new Function('return this')(),gcv=\\\\\\"__coverage__\\\\\\",coverageData={path:\\\\\\"/fixtures/basic.js\\\\\\",statementMap:{\\\\\\"0\\\\\\":{start:{line:1,column:0},end:{line:11,column:2}},\\\\\\"1\\\\\\":{start:{line:4,column:4},end:{line:4,column:18}},\\\\\\"2\\\\\\":{start:{line:8,column:4},end:{line:8,column:23}}},fnMap:{\\\\\\"0\\\\\\":{name:\\\\\\"(anonymous_0)\\\\\\",decl:{start:{line:3,column:2},end:{line:3,column:3}},loc:{start:{line:3,column:8},end:{line:5,column:3}},line:3},\\\\\\"1\\\\\\":{name:\\\\\\"(anonymous_1)\\\\\\",decl:{start:{line:7,column:2},end:{line:7,column:3}},loc:{start:{line:7,column:8},end:{line:9,column:3}},line:7}},branchMap:{},s:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0,\\\\\\"2\\\\\\":0},f:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0},b:{},_coverageSchema:\\\\\\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\\\\\"},coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}coverageData.hash=hash;return coverage[path]=coverageData;}();++cov_1v2zerd2hz.s[0];module.exports=class Foo{bar(){++cov_1v2zerd2hz.f[0];++cov_1v2zerd2hz.s[1];return!!this;}baz(){++cov_1v2zerd2hz.f[1];++cov_1v2zerd2hz.s[2];return!this.bar();}};\\\\n\\\\n\\\\n//////////////////\\\\n// WEBPACK FOOTER\\\\n// ./test/fixtures/basic.js\\\\n// module id = 0\\\\n// module chunks = 0\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`errors 1`] = `Array []`; exports[`errors 2`] = `Array []`; exports[`instrument code 1`] = ` -"/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = \\"\\"; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ +"webpackJsonp([0],[ /* 0 */ /***/ (function(module, exports) { -var cov_2obfoewtj5=function(){var path=\\"/fixtures/basic.js\\",hash=\\"d160bda36fc8432c2ffbb2cefc3c20475fdbdbec\\",global=new Function('return this')(),gcv=\\"__coverage__\\",coverageData={path:\\"/fixtures/basic.js\\",statementMap:{\\"0\\":{start:{line:1,column:0},end:{line:11,column:2}},\\"1\\":{start:{line:4,column:4},end:{line:4,column:18}},\\"2\\":{start:{line:8,column:4},end:{line:8,column:23}}},fnMap:{\\"0\\":{name:\\"(anonymous_0)\\",decl:{start:{line:3,column:2},end:{line:3,column:3}},loc:{start:{line:3,column:8},end:{line:5,column:3}},line:3},\\"1\\":{name:\\"(anonymous_1)\\",decl:{start:{line:7,column:2},end:{line:7,column:3}},loc:{start:{line:7,column:8},end:{line:9,column:3}},line:7}},branchMap:{},s:{\\"0\\":0,\\"1\\":0,\\"2\\":0},f:{\\"0\\":0,\\"1\\":0},b:{},_coverageSchema:\\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\"},coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}coverageData.hash=hash;return coverage[path]=coverageData;}();++cov_2obfoewtj5.s[0];module.exports=class Foo{bar(){++cov_2obfoewtj5.f[0];++cov_2obfoewtj5.s[1];return!!this;}baz(){++cov_2obfoewtj5.f[1];++cov_2obfoewtj5.s[2];return!this.bar();}}; +var cov_1v2zerd2hz=function(){var path=\\"/fixtures/basic.js\\",hash=\\"f67bc5731c59e70932ca6e13967f6329cc8682d3\\",global=new Function('return this')(),gcv=\\"__coverage__\\",coverageData={path:\\"/fixtures/basic.js\\",statementMap:{\\"0\\":{start:{line:1,column:0},end:{line:11,column:2}},\\"1\\":{start:{line:4,column:4},end:{line:4,column:18}},\\"2\\":{start:{line:8,column:4},end:{line:8,column:23}}},fnMap:{\\"0\\":{name:\\"(anonymous_0)\\",decl:{start:{line:3,column:2},end:{line:3,column:3}},loc:{start:{line:3,column:8},end:{line:5,column:3}},line:3},\\"1\\":{name:\\"(anonymous_1)\\",decl:{start:{line:7,column:2},end:{line:7,column:3}},loc:{start:{line:7,column:8},end:{line:9,column:3}},line:7}},branchMap:{},s:{\\"0\\":0,\\"1\\":0,\\"2\\":0},f:{\\"0\\":0,\\"1\\":0},b:{},_coverageSchema:\\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\"},coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}coverageData.hash=hash;return coverage[path]=coverageData;}();++cov_1v2zerd2hz.s[0];module.exports=class Foo{bar(){++cov_1v2zerd2hz.f[0];++cov_1v2zerd2hz.s[1];return!!this;}baz(){++cov_1v2zerd2hz.f[1];++cov_1v2zerd2hz.s[2];return!this.bar();}}; /***/ }) -/******/ ]);" +],[0]);" `; -exports[`sourcemap files on by default 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///webpack/bootstrap 1ae028e11f9e6449a2dd\\",\\"webpack:///./test/fixtures/basic.js\\"],\\"names\\":[\\"module\\",\\"exports\\",\\"Foo\\",\\"bar\\",\\"baz\\"],\\"mappings\\":\\";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;mlCC7DAA,OAAOC,OAAP,CAAiB,KAAMC,IAAI,CAEzBC,KAAM,6CACJ,MAAO,CAAC,CAAC,IAAT,CACD,CAEDC,KAAM,6CACJ,MAAO,CAAC,KAAKD,GAAL,EAAR,CACD,CARwB,CAA3B,C\\",\\"file\\":\\"main.js\\",\\"sourcesContent\\":[\\" \\\\t// The module cache\\\\n \\\\tvar installedModules = {};\\\\n\\\\n \\\\t// The require function\\\\n \\\\tfunction __webpack_require__(moduleId) {\\\\n\\\\n \\\\t\\\\t// Check if module is in cache\\\\n \\\\t\\\\tif(installedModules[moduleId]) {\\\\n \\\\t\\\\t\\\\treturn installedModules[moduleId].exports;\\\\n \\\\t\\\\t}\\\\n \\\\t\\\\t// Create a new module (and put it into the cache)\\\\n \\\\t\\\\tvar module = installedModules[moduleId] = {\\\\n \\\\t\\\\t\\\\ti: moduleId,\\\\n \\\\t\\\\t\\\\tl: false,\\\\n \\\\t\\\\t\\\\texports: {}\\\\n \\\\t\\\\t};\\\\n\\\\n \\\\t\\\\t// Execute the module function\\\\n \\\\t\\\\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\\\\n\\\\n \\\\t\\\\t// Flag the module as loaded\\\\n \\\\t\\\\tmodule.l = true;\\\\n\\\\n \\\\t\\\\t// Return the exports of the module\\\\n \\\\t\\\\treturn module.exports;\\\\n \\\\t}\\\\n\\\\n\\\\n \\\\t// expose the modules object (__webpack_modules__)\\\\n \\\\t__webpack_require__.m = modules;\\\\n\\\\n \\\\t// expose the module cache\\\\n \\\\t__webpack_require__.c = installedModules;\\\\n\\\\n \\\\t// define getter function for harmony exports\\\\n \\\\t__webpack_require__.d = function(exports, name, getter) {\\\\n \\\\t\\\\tif(!__webpack_require__.o(exports, name)) {\\\\n \\\\t\\\\t\\\\tObject.defineProperty(exports, name, {\\\\n \\\\t\\\\t\\\\t\\\\tconfigurable: false,\\\\n \\\\t\\\\t\\\\t\\\\tenumerable: true,\\\\n \\\\t\\\\t\\\\t\\\\tget: getter\\\\n \\\\t\\\\t\\\\t});\\\\n \\\\t\\\\t}\\\\n \\\\t};\\\\n\\\\n \\\\t// getDefaultExport function for compatibility with non-harmony modules\\\\n \\\\t__webpack_require__.n = function(module) {\\\\n \\\\t\\\\tvar getter = module && module.__esModule ?\\\\n \\\\t\\\\t\\\\tfunction getDefault() { return module['default']; } :\\\\n \\\\t\\\\t\\\\tfunction getModuleExports() { return module; };\\\\n \\\\t\\\\t__webpack_require__.d(getter, 'a', getter);\\\\n \\\\t\\\\treturn getter;\\\\n \\\\t};\\\\n\\\\n \\\\t// Object.prototype.hasOwnProperty.call\\\\n \\\\t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\\\\n\\\\n \\\\t// __webpack_public_path__\\\\n \\\\t__webpack_require__.p = \\\\\\"\\\\\\";\\\\n\\\\n \\\\t// Load entry module and return exports\\\\n \\\\treturn __webpack_require__(__webpack_require__.s = 0);\\\\n\\\\n\\\\n\\\\n// WEBPACK FOOTER //\\\\n// webpack/bootstrap 1ae028e11f9e6449a2dd\\",\\"module.exports = class Foo {\\\\n\\\\n bar() {\\\\n return !!this;\\\\n }\\\\n\\\\n baz() {\\\\n return !this.bar();\\\\n }\\\\n\\\\n};\\\\n\\\\n\\\\n\\\\n// WEBPACK FOOTER //\\\\n// ./test/fixtures/basic.js\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`sourcemap files on by default 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:////fixtures/basic.js\\"],\\"names\\":[\\"module\\",\\"exports\\",\\"Foo\\",\\"bar\\",\\"baz\\"],\\"mappings\\":\\";;;;68BAAAA,OAAOC,OAAP,CAAiB,KAAMC,IAAI,CAEzBC,KAAM,6CACJ,MAAO,CAAC,CAAC,IAAT,CACD,CAEDC,KAAM,6CACJ,MAAO,CAAC,KAAKD,GAAL,EAAR,CACD,CARwB,CAA3B,C\\",\\"file\\":\\"main.js\\",\\"sourcesContent\\":[\\"module.exports = class Foo {\\\\n\\\\n bar() {\\\\n return !!this;\\\\n }\\\\n\\\\n baz() {\\\\n return !this.bar();\\\\n }\\\\n\\\\n};\\\\n\\\\n\\\\n\\\\n// WEBPACK FOOTER //\\\\n// /fixtures/basic.js\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`warnings 1`] = `Array []`; diff --git a/test/helpers.js b/test/helpers.js deleted file mode 100644 index bd226ab..0000000 --- a/test/helpers.js +++ /dev/null @@ -1,4 +0,0 @@ -export function stripLocalPaths(source) { // eslint-disable-line import/prefer-default-export - const regexpReplace = new RegExp(__dirname, 'g'); - return source.replace(regexpReplace, ''); -} diff --git a/test/index.test.js b/test/index.test.js index 0506f7a..9af9a5e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,9 +1,8 @@ -import webpack from './webpack'; -import { stripLocalPaths } from './helpers'; +import webpack from './utils/webpack'; test('instrument code', async () => { const stats = await webpack(); - const instrumentedSource = stripLocalPaths(stats.compilation.assets['main.js'].source()); + const instrumentedSource = stats.compilation.assets['main.js'].source(); expect(instrumentedSource).toMatchSnapshot(); }); diff --git a/test/utils/loader.js b/test/utils/loader.js new file mode 100644 index 0000000..ec2354a --- /dev/null +++ b/test/utils/loader.js @@ -0,0 +1,11 @@ +import path from 'path'; +import loader from '../../src/cjs'; + +module.exports = function (...args) { + // hack the resourcePath to be consistent across systems so that tests always work + this.resourcePath = this.resourcePath + .replace(path.resolve(__dirname, '..'), '') + // make windows paths appear like unix + .replace(/\\/g, '/'); + return loader.call(this, ...args); +}; diff --git a/test/webpack.js b/test/utils/webpack.js similarity index 70% rename from test/webpack.js rename to test/utils/webpack.js index 329bd20..f43cc0a 100644 --- a/test/webpack.js +++ b/test/utils/webpack.js @@ -2,13 +2,13 @@ import path from 'path'; import webpack from 'webpack'; import MemoryFileSystem from 'memory-fs'; -const loader = require.resolve('../src/cjs.js'); +const loader = require.resolve('./loader'); export default function ({ fixture = 'basic.js', options, extend = {} } = {}) { const config = { - entry: path.join(__dirname, 'fixtures', fixture), + entry: path.join(__dirname, '..', 'fixtures', fixture), output: { - path: path.join(__dirname, 'fixtures', 'dist'), + path: path.join(__dirname, '..', 'fixtures', 'dist'), }, module: { rules: [{ @@ -19,6 +19,11 @@ export default function ({ fixture = 'basic.js', options, extend = {} } = {}) { }], }, ...extend, + plugins: [ + new webpack.optimize.CommonsChunkPlugin({ + name: 'manifest', + }), + ], }; return new Promise((resolve, reject) => { From ef94627ccb760b12e01a6508ff194e7ca24698a9 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Mon, 10 Jul 2017 22:11:29 +0100 Subject: [PATCH 2/2] fix: pass sourcemaps to istanbul --- package-lock.json | 42 +++++++++++++++++++++++++-- package.json | 2 ++ src/index.js | 14 +++++++-- test/__snapshots__/index.test.js.snap | 9 +++--- test/fixtures/basic.js | 4 --- test/index.test.js | 4 +-- test/utils/loader.js | 19 ++++++++---- test/utils/webpack.js | 3 ++ 8 files changed, 77 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11ab64c..8115869 100644 --- a/package-lock.json +++ b/package-lock.json @@ -507,6 +507,17 @@ "babel-preset-jest": "20.0.3" } }, + "babel-loader": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-7.1.1.tgz", + "integrity": "sha1-uHE0yLEuPkwqlOBUYIW8aAorhIg=", + "dev": true, + "requires": { + "find-cache-dir": "1.0.0", + "loader-utils": "1.1.0", + "mkdirp": "0.5.1" + } + }, "babel-messages": { "version": "6.23.0", "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz", @@ -1455,6 +1466,12 @@ "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", "dev": true }, + "commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", + "dev": true + }, "compare-func": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-1.3.2.tgz", @@ -1721,8 +1738,7 @@ "convert-source-map": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.0.tgz", - "integrity": "sha1-ms1whRxtXf3ZPZKC5e35SgP/RrU=", - "dev": true + "integrity": "sha1-ms1whRxtXf3ZPZKC5e35SgP/RrU=" }, "core-js": { "version": "2.4.1", @@ -2669,6 +2685,28 @@ "integrity": "sha1-w8T2xmO5I0WamqKZEtLQMfFQf4Q=", "dev": true }, + "find-cache-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-1.0.0.tgz", + "integrity": "sha1-kojj6ePMN0hxfTnq3hfPcfww7m8=", + "dev": true, + "requires": { + "commondir": "1.0.1", + "make-dir": "1.0.0", + "pkg-dir": "2.0.0" + }, + "dependencies": { + "pkg-dir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz", + "integrity": "sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s=", + "dev": true, + "requires": { + "find-up": "2.1.0" + } + } + } + }, "find-up": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", diff --git a/package.json b/package.json index 9ccf8b3..6cf8995 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dist" ], "dependencies": { + "convert-source-map": "^1.5.0", "istanbul-lib-instrument": "^1.7.3", "loader-utils": "^1.1.0" }, @@ -39,6 +40,7 @@ "devDependencies": { "babel-cli": "^6.24.0", "babel-jest": "^20.0.3", + "babel-loader": "^7.1.1", "babel-plugin-transform-object-rest-spread": "^6.23.0", "babel-polyfill": "^6.23.0", "babel-preset-env": "^1.6.0", diff --git a/src/index.js b/src/index.js index 9fb49a9..194f367 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,21 @@ import { createInstrumenter } from 'istanbul-lib-instrument'; import loaderUtils from 'loader-utils'; +import convert from 'convert-source-map'; + +export default function (source, sourceMap) { + let srcMap = sourceMap; + // use inline source map, if any + if (!srcMap) { + const inlineSourceMap = convert.fromSource(source); + if (inlineSourceMap) { + srcMap = inlineSourceMap.sourcemap; + } + } -export default function (source) { const options = Object.assign({ produceSourceMap: true }, loaderUtils.getOptions(this)); const instrumenter = createInstrumenter(options); instrumenter.instrument(source, this.resourcePath, (error, instrumentedSource) => { this.callback(error, instrumentedSource, instrumenter.lastSourceMap()); - }); + }, srcMap); } diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 098e78e..c2b479b 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`disabled sourcemaps 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///./test/fixtures/basic.js\\"],\\"names\\":[],\\"mappings\\":\\";;;;AAAA,8BAA8B,oJAAoJ,wCAAwC,KAAK,OAAO,gBAAgB,MAAM,kBAAkB,MAAM,OAAO,gBAAgB,MAAM,kBAAkB,MAAM,OAAO,gBAAgB,MAAM,mBAAmB,QAAQ,KAAK,2BAA2B,OAAO,gBAAgB,MAAM,iBAAiB,MAAM,OAAO,gBAAgB,MAAM,iBAAiB,QAAQ,MAAM,2BAA2B,OAAO,gBAAgB,MAAM,iBAAiB,MAAM,OAAO,gBAAgB,MAAM,iBAAiB,SAAS,aAAa,IAAI,kBAAkB,IAAI,YAAY,KAAK,4DAA4D,sCAAsC,EAAE,+CAA+C,uBAAuB,uBAAuB,oCAAoC,GAAG,sBAAsB,yBAAyB,MAAM,sBAAsB,sBAAsB,cAAc,MAAM,sBAAsB,sBAAsB,qB\\",\\"file\\":\\"main.js\\",\\"sourcesContent\\":[\\"var cov_1v2zerd2hz=function(){var path=\\\\\\"/fixtures/basic.js\\\\\\",hash=\\\\\\"f67bc5731c59e70932ca6e13967f6329cc8682d3\\\\\\",global=new Function('return this')(),gcv=\\\\\\"__coverage__\\\\\\",coverageData={path:\\\\\\"/fixtures/basic.js\\\\\\",statementMap:{\\\\\\"0\\\\\\":{start:{line:1,column:0},end:{line:11,column:2}},\\\\\\"1\\\\\\":{start:{line:4,column:4},end:{line:4,column:18}},\\\\\\"2\\\\\\":{start:{line:8,column:4},end:{line:8,column:23}}},fnMap:{\\\\\\"0\\\\\\":{name:\\\\\\"(anonymous_0)\\\\\\",decl:{start:{line:3,column:2},end:{line:3,column:3}},loc:{start:{line:3,column:8},end:{line:5,column:3}},line:3},\\\\\\"1\\\\\\":{name:\\\\\\"(anonymous_1)\\\\\\",decl:{start:{line:7,column:2},end:{line:7,column:3}},loc:{start:{line:7,column:8},end:{line:9,column:3}},line:7}},branchMap:{},s:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0,\\\\\\"2\\\\\\":0},f:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0},b:{},_coverageSchema:\\\\\\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\\\\\"},coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}coverageData.hash=hash;return coverage[path]=coverageData;}();++cov_1v2zerd2hz.s[0];module.exports=class Foo{bar(){++cov_1v2zerd2hz.f[0];++cov_1v2zerd2hz.s[1];return!!this;}baz(){++cov_1v2zerd2hz.f[1];++cov_1v2zerd2hz.s[2];return!this.bar();}};\\\\n\\\\n\\\\n//////////////////\\\\n// WEBPACK FOOTER\\\\n// ./test/fixtures/basic.js\\\\n// module id = 0\\\\n// module chunks = 0\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`disabled sourcemaps 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///./test/fixtures/basic.js\\"],\\"names\\":[],\\"mappings\\":\\"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\\",\\"file\\":\\"main.js\\",\\"sourcesContent\\":[\\"\\\\\\"use strict\\\\\\";var cov_1v2zerd2hz=function(){var path=\\\\\\"/fixtures/basic.js\\\\\\",hash=\\\\\\"9f43b4cb30c68c93d6983a04852457a950700587\\\\\\",global=new Function('return this')(),gcv=\\\\\\"__coverage__\\\\\\",coverageData={path:\\\\\\"/fixtures/basic.js\\\\\\",statementMap:{\\\\\\"0\\\\\\":{start:{line:3,column:19},end:{line:3,column:563}},\\\\\\"1\\\\\\":{start:{line:3,column:76},end:{line:3,column:347}},\\\\\\"2\\\\\\":{start:{line:3,column:134},end:{line:3,column:142}},\\\\\\"3\\\\\\":{start:{line:3,column:144},end:{line:3,column:199}},\\\\\\"4\\\\\\":{start:{line:3,column:200},end:{line:3,column:231}},\\\\\\"5\\\\\\":{start:{line:3,column:232},end:{line:3,column:286}},\\\\\\"6\\\\\\":{start:{line:3,column:259},end:{line:3,column:286}},\\\\\\"7\\\\\\":{start:{line:3,column:287},end:{line:3,column:345}},\\\\\\"8\\\\\\":{start:{line:3,column:350},end:{line:3,column:559}},\\\\\\"9\\\\\\":{start:{line:3,column:407},end:{line:3,column:475}},\\\\\\"10\\\\\\":{start:{line:3,column:423},end:{line:3,column:475}},\\\\\\"11\\\\\\":{start:{line:3,column:476},end:{line:3,column:536}},\\\\\\"12\\\\\\":{start:{line:3,column:493},end:{line:3,column:536}},\\\\\\"13\\\\\\":{start:{line:3,column:537},end:{line:3,column:556}},\\\\\\"14\\\\\\":{start:{line:5,column:50},end:{line:5,column:151}},\\\\\\"15\\\\\\":{start:{line:5,column:92},end:{line:5,column:149}},\\\\\\"16\\\\\\":{start:{line:7,column:0},end:{line:20,column:4}},\\\\\\"17\\\\\\":{start:{line:9,column:4},end:{line:9,column:31}},\\\\\\"18\\\\\\":{start:{line:12,column:2},end:{line:17,column:6}},\\\\\\"19\\\\\\":{start:{line:15,column:6},end:{line:15,column:20}},\\\\\\"20\\\\\\":{start:{line:19,column:2},end:{line:19,column:13}}},fnMap:{\\\\\\"0\\\\\\":{name:\\\\\\"(anonymous_0)\\\\\\",decl:{start:{line:3,column:19},end:{line:3,column:20}},loc:{start:{line:3,column:31},end:{line:3,column:561}},line:3},\\\\\\"1\\\\\\":{name:\\\\\\"defineProperties\\\\\\",decl:{start:{line:3,column:42},end:{line:3,column:58}},loc:{start:{line:3,column:74},end:{line:3,column:349}},line:3},\\\\\\"2\\\\\\":{name:\\\\\\"(anonymous_2)\\\\\\",decl:{start:{line:3,column:357},end:{line:3,column:358}},loc:{start:{line:3,column:405},end:{line:3,column:558}},line:3},\\\\\\"3\\\\\\":{name:\\\\\\"_classCallCheck\\\\\\",decl:{start:{line:5,column:9},end:{line:5,column:24}},loc:{start:{line:5,column:48},end:{line:5,column:153}},line:5},\\\\\\"4\\\\\\":{name:\\\\\\"(anonymous_4)\\\\\\",decl:{start:{line:7,column:17},end:{line:7,column:18}},loc:{start:{line:7,column:29},end:{line:20,column:1}},line:7},\\\\\\"5\\\\\\":{name:\\\\\\"Foo\\\\\\",decl:{start:{line:8,column:11},end:{line:8,column:14}},loc:{start:{line:8,column:17},end:{line:10,column:3}},line:8},\\\\\\"6\\\\\\":{name:\\\\\\"bar\\\\\\",decl:{start:{line:14,column:20},end:{line:14,column:23}},loc:{start:{line:14,column:26},end:{line:16,column:5}},line:14}},branchMap:{\\\\\\"0\\\\\\":{loc:{start:{line:3,column:168},end:{line:3,column:198}},type:\\\\\\"binary-expr\\\\\\",locations:[{start:{line:3,column:168},end:{line:3,column:189}},{start:{line:3,column:193},end:{line:3,column:198}}],line:3},\\\\\\"1\\\\\\":{loc:{start:{line:3,column:232},end:{line:3,column:286}},type:\\\\\\"if\\\\\\",locations:[{start:{line:3,column:232},end:{line:3,column:286}},{start:{line:3,column:232},end:{line:3,column:286}}],line:3},\\\\\\"2\\\\\\":{loc:{start:{line:3,column:407},end:{line:3,column:475}},type:\\\\\\"if\\\\\\",locations:[{start:{line:3,column:407},end:{line:3,column:475}},{start:{line:3,column:407},end:{line:3,column:475}}],line:3},\\\\\\"3\\\\\\":{loc:{start:{line:3,column:476},end:{line:3,column:536}},type:\\\\\\"if\\\\\\",locations:[{start:{line:3,column:476},end:{line:3,column:536}},{start:{line:3,column:476},end:{line:3,column:536}}],line:3},\\\\\\"4\\\\\\":{loc:{start:{line:5,column:50},end:{line:5,column:151}},type:\\\\\\"if\\\\\\",locations:[{start:{line:5,column:50},end:{line:5,column:151}},{start:{line:5,column:50},end:{line:5,column:151}}],line:5}},s:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0,\\\\\\"2\\\\\\":0,\\\\\\"3\\\\\\":0,\\\\\\"4\\\\\\":0,\\\\\\"5\\\\\\":0,\\\\\\"6\\\\\\":0,\\\\\\"7\\\\\\":0,\\\\\\"8\\\\\\":0,\\\\\\"9\\\\\\":0,\\\\\\"10\\\\\\":0,\\\\\\"11\\\\\\":0,\\\\\\"12\\\\\\":0,\\\\\\"13\\\\\\":0,\\\\\\"14\\\\\\":0,\\\\\\"15\\\\\\":0,\\\\\\"16\\\\\\":0,\\\\\\"17\\\\\\":0,\\\\\\"18\\\\\\":0,\\\\\\"19\\\\\\":0,\\\\\\"20\\\\\\":0},f:{\\\\\\"0\\\\\\":0,\\\\\\"1\\\\\\":0,\\\\\\"2\\\\\\":0,\\\\\\"3\\\\\\":0,\\\\\\"4\\\\\\":0,\\\\\\"5\\\\\\":0,\\\\\\"6\\\\\\":0},b:{\\\\\\"0\\\\\\":[0,0],\\\\\\"1\\\\\\":[0,0],\\\\\\"2\\\\\\":[0,0],\\\\\\"3\\\\\\":[0,0],\\\\\\"4\\\\\\":[0,0]},inputSourceMap:{version:3,sources:[\\\\\\"test/fixtures/basic.js\\\\\\"],names:[\\\\\\"module\\\\\\",\\\\\\"exports\\\\\\"],mappings:\\\\\\";;;;;;AAAAA,OAAOC,OAAP;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,0BAEQ;AACJ,aAAO,CAAC,CAAC,IAAT;AACD;AAJH;;AAAA;AAAA\\\\\\",file:\\\\\\"basic.js\\\\\\",sourceRoot:\\\\\\"\\\\\\",sourcesContent:[\\\\\\"module.exports = class Foo {\\\\\\\\n\\\\\\\\n bar() {\\\\\\\\n return !!this;\\\\\\\\n }\\\\\\\\n\\\\\\\\n};\\\\\\\\n\\\\\\"]},_coverageSchema:\\\\\\"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c\\\\\\"},coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}coverageData.hash=hash;return coverage[path]=coverageData;}();var _createClass=(++cov_1v2zerd2hz.s[0],function(){++cov_1v2zerd2hz.f[0];function defineProperties(target,props){++cov_1v2zerd2hz.f[1];++cov_1v2zerd2hz.s[1];for(var i=0;i { test('sourcemap files on by default', async () => { const stats = await webpack({ extend: { - devtool: 'sourcemap', + devtool: 'source-map', }, }); const sourceMap = stats.compilation.assets['main.js.map'].source(); @@ -21,7 +21,7 @@ test('sourcemap files on by default', async () => { test('disabled sourcemaps', async () => { const stats = await webpack({ extend: { - devtool: 'sourcemap', + devtool: 'source-map', }, options: { produceSourceMap: false, diff --git a/test/utils/loader.js b/test/utils/loader.js index ec2354a..fa61043 100644 --- a/test/utils/loader.js +++ b/test/utils/loader.js @@ -1,11 +1,18 @@ import path from 'path'; import loader from '../../src/cjs'; -module.exports = function (...args) { +const normalize = str => str.split(path.sep).join('/'); + +module.exports = function (source, map, ...args) { // hack the resourcePath to be consistent across systems so that tests always work - this.resourcePath = this.resourcePath - .replace(path.resolve(__dirname, '..'), '') - // make windows paths appear like unix - .replace(/\\/g, '/'); - return loader.call(this, ...args); + this.resourcePath = normalize(this.resourcePath.replace(path.resolve(__dirname, '..'), '')); + + // do the same hack for sourcemaps so tests are consistent + const sourceMap = map; + if (sourceMap) { + sourceMap.sourceRoot = ''; + sourceMap.sources = sourceMap.sources.map(normalize); + } + + return loader.call(this, source, sourceMap, ...args); }; diff --git a/test/utils/webpack.js b/test/utils/webpack.js index f43cc0a..cab504d 100644 --- a/test/utils/webpack.js +++ b/test/utils/webpack.js @@ -12,6 +12,9 @@ export default function ({ fixture = 'basic.js', options, extend = {} } = {}) { }, module: { rules: [{ + test: /\.js$/, + loader: 'babel-loader', + }, { test: /\.js$/, loader, enforce: 'post',