diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7d5bc03d80..460130a5658 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,8 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 + with: + node-version: '12' - name: Install Packages run: npm install - name: Test diff --git a/karma.conf.js b/karma.conf.js index 974c8972136..05f1a1ceb6e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,5 +1,6 @@ "use strict"; const os = require("os"); +const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); if (os.arch() === "arm64") { @@ -20,12 +21,11 @@ module.exports = function(config) { * frameworks to use * available frameworks: https://npmjs.org/browse/keyword/karma-adapter */ - frameworks: ["mocha"], + frameworks: ["mocha", "webpack"], // list of files / patterns to load in the browser files: [ - "build/eslint.js", "tests/lib/linter/linter.js" ], @@ -44,6 +44,14 @@ module.exports = function(config) { }, webpack: { mode: "none", + plugins: [ + new NodePolyfillPlugin() + ], + resolve: { + alias: { + "../../../lib/linter$": "../../../build/eslint.js" + } + }, stats: "errors-only" }, webpackMiddleware: { diff --git a/package.json b/package.json index cdf5a4b180e..3a34facf5a3 100644 --- a/package.json +++ b/package.json @@ -108,11 +108,11 @@ "fs-teardown": "^0.1.0", "glob": "^7.1.6", "jsdoc": "^3.5.5", - "karma": "^4.0.1", + "karma": "^6.1.1", "karma-chrome-launcher": "^3.1.0", - "karma-mocha": "^1.3.0", - "karma-mocha-reporter": "^2.2.3", - "karma-webpack": "^4.0.0-rc.6", + "karma-mocha": "^2.0.1", + "karma-mocha-reporter": "^2.2.5", + "karma-webpack": "^5.0.0", "lint-staged": "^10.1.2", "load-perf": "^0.2.0", "markdownlint": "^0.19.0", @@ -120,6 +120,7 @@ "memfs": "^3.0.1", "mocha": "^7.1.1", "mocha-junit-reporter": "^1.23.0", + "node-polyfill-webpack-plugin": "^1.0.3", "npm-license": "^0.3.3", "nyc": "^15.0.1", "proxyquire": "^2.0.1", @@ -129,8 +130,8 @@ "shelljs": "^0.8.2", "sinon": "^9.0.1", "temp": "^0.9.0", - "webpack": "^4.35.0", - "webpack-cli": "^3.3.5", + "webpack": "^5.23.0", + "webpack-cli": "^4.5.0", "yorkie": "^2.0.0" }, "keywords": [ diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index f999dd3ad9d..976bd765755 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -5,27 +5,6 @@ "use strict"; -//------------------------------------------------------------------------------ -// Helper -//------------------------------------------------------------------------------ - -/** - * To make sure this works in both browsers and Node.js - * @param {string} name Name of the module to require - * @param {Object} windowName name of the window - * @returns {Object} Required object - * @private - */ -function compatRequire(name, windowName) { - if (typeof window === "object") { // eslint-disable-line no-undef - return window[windowName || name]; // eslint-disable-line no-undef - } - if (typeof require === "function") { - return require(name); - } - throw new Error(`Cannot find object '${name}'.`); -} - //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ @@ -35,7 +14,7 @@ const assert = require("chai").assert, esprima = require("esprima"), testParsers = require("../../fixtures/parsers/linter-test-parsers"); -const { Linter } = compatRequire("../../../lib/linter", "eslint"); +const { Linter } = require("../../../lib/linter"); //------------------------------------------------------------------------------ // Constants diff --git a/webpack.config.js b/webpack.config.js index 2b56290b346..b256f442460 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,7 @@ "use strict"; +const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); +/** @type {import("webpack").Configuration} */ module.exports = { mode: "none", entry: { @@ -42,6 +44,9 @@ module.exports = { } ] }, + plugins: [ + new NodePolyfillPlugin() + ], resolve: { mainFields: ["browser", "main", "module"] },