diff --git a/package.json b/package.json index fa473f2d4..9511c4d17 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "test": "run-s test-node test-headless test-webworker test-es-module", "check-dependencies": "dependency-check package.json --unused --no-dev --ignore-module coveralls --ignore-module @std/esm", "build": "node ./build.js", - "lint": "eslint .", + "lint": "run-p lint-js lint-mjs lint-markdown", + "lint-js": "eslint .", + "lint-mjs": "eslint --ext mjs --parser-options=sourceType:module test/es2015", "lint-markdown": "find docs -type f -name '*.md' ! -name 'changelog.md' | xargs markdownlint", "precommit": "lint-staged", "pretest-webworker": "npm run build", @@ -35,6 +37,7 @@ }, "lint-staged": { "*.js": "eslint", + "*.mjs": "eslint --ext mjs --parser-options=sourceType:module", "docs/**/*.md": "markdownlint" }, "dependencies": { diff --git a/test/es2015/a-function-module.mjs b/test/es2015/a-function-module.mjs index 57072ba8c..8883e9ed8 100644 --- a/test/es2015/a-function-module.mjs +++ b/test/es2015/a-function-module.mjs @@ -1 +1 @@ -export default function (){ return 42; } +export default function () { return 42; } diff --git a/test/es2015/a-module-with-default.mjs b/test/es2015/a-module-with-default.mjs index 65ac3455c..eb591ba30 100644 --- a/test/es2015/a-module-with-default.mjs +++ b/test/es2015/a-module-with-default.mjs @@ -1,3 +1,3 @@ export default { - anExport(){ return 42; } -} + anExport() { return 42; } +}; diff --git a/test/es2015/a-module.mjs b/test/es2015/a-module.mjs index 8a6622ebe..f2f654fa1 100644 --- a/test/es2015/a-module.mjs +++ b/test/es2015/a-module.mjs @@ -1 +1 @@ -export function anExport(){ return 42; } +export function anExport() { return 42; } diff --git a/test/es2015/module-support-assessment-test.mjs b/test/es2015/module-support-assessment-test.mjs index eb9a830e9..ff297aa38 100644 --- a/test/es2015/module-support-assessment-test.mjs +++ b/test/es2015/module-support-assessment-test.mjs @@ -1,31 +1,33 @@ -"use strict"; + import referee from "referee"; import sinon from "../../lib/sinon"; import * as aModule from "./a-module"; import aModuleWithDefaultExport from "./a-module-with-default"; + +// Usually one would import the default module, but one can make a form of wrapper like this +/* eslint-disable no-unused-vars */ import functionModule, * as functionModuleAlternative from "./a-function-module"; const {assert, refute} = referee; -function createTestSuite(action){ +function createTestSuite(action) { var stub; var errorRegEx = /TypeError: ES Modules cannot be (stubbed|spied)/; - afterEach(function() { - stub && stub.restore && stub.restore(); - }); + describe("sinon." + action + "()", function () { - describe("sinon." + action + "()", function(){ - describe("Modules with objects as their default export", function() { - afterEach(function() { - stub && stub.restore && stub.restore(); - }); - it("should NOT result in error", function() { - refute.exception(function() { + afterEach(function () { + if (stub && stub.restore) { stub.restore(); } + }); + + describe("Modules with objects as their default export", function () { + + it("should NOT result in error", function () { + refute.exception(function () { stub = sinon[action](aModuleWithDefaultExport, "anExport"); }); }); - it("should spy/stub an exported function", function() { + it("should spy/stub an exported function", function () { stub = sinon[action](aModuleWithDefaultExport, "anExport"); aModuleWithDefaultExport.anExport(); aModuleWithDefaultExport.anExport(); @@ -33,17 +35,17 @@ function createTestSuite(action){ }); }); - describe("Modules without default export", function() { - it("should give a proper error message", function() { - assert.exception(function() { + describe("Modules without default export", function () { + it("should give a proper error message", function () { + assert.exception(function () { sinon[action](aModule, "anExport"); }, errorRegEx); }); }); - describe("Modules that exports a function as their default export", function() { - it("should not be possible to spy/stub the default export using a wrapper for the exports", function() { - assert.exception(function() { + describe("Modules that exports a function as their default export", function () { + it("should not be possible to spy/stub the default export using a wrapper for the exports", function () { + assert.exception(function () { stub = sinon[action](functionModuleAlternative, "anExport"); }, errorRegEx); }); @@ -51,5 +53,5 @@ function createTestSuite(action){ }); } -createTestSuite('stub'); -createTestSuite('spy'); +createTestSuite("stub"); +createTestSuite("spy");