Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Jul 7, 2023
1 parent d17f672 commit fe2e76f
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions tests/lib/linter/linter.js
Expand Up @@ -9,6 +9,9 @@
// Requirements
//------------------------------------------------------------------------------

import { mock, fn } from "@wdio/browser-runner"
import { expect } from "@wdio/globals"

const { assert } = require("chai"),
sinon = require("sinon"),
espree = require("espree"),
Expand All @@ -17,6 +20,22 @@ const { assert } = require("chai"),

const { FlatConfigArray } = require("../../../lib/config/flat-config-array");
const { Linter } = require("../../../build/eslint.js");
const StubParser = require("../../fixtures/parsers/stub-parser.js")

//------------------------------------------------------------------------------
// Mocks
//------------------------------------------------------------------------------
mock('../../fixtures/parsers/stub-parser.js', () => ({
parse: fn().mockReturnValue({
type: "Program",
loc: {},
range: [],
body: [],
comments: [],
errors: [],
tokens: []
})
}))

//------------------------------------------------------------------------------
// Constants
Expand Down Expand Up @@ -7266,14 +7285,15 @@ var a = "test2";
/**
* fails due to "ES Modules cannot be spied"
*/
it.skip("should have file path passed to it", () => {
it("should have file path passed to it", () => {
const code = "/* this is code */";
const parseSpy = sinon.spy(testParsers.stubParser, "parse");

linter.defineParser("stub-parser", testParsers.stubParser);
linter.verify(code, { parser: "stub-parser" }, filename, true);

sinon.assert.calledWithMatch(parseSpy, "", { filePath: filename });
expect(StubParser.parse).toBeCalledTimes(1);
const [arg0, arg1] = StubParser.parse.mock.calls[0];
expect(arg0).toBe(code);
expect(arg1.filePath).toBe(filename);
});

it("should not report an error when JSX code contains a spread operator and JSX is enabled", () => {
Expand Down Expand Up @@ -7516,6 +7536,10 @@ var a = "test2";
assert.strictEqual(messages.length, 0);
assert.strictEqual(suppressedMessages.length, 0);
});

beforeEach(() => {
StubParser.parse.mockClear()
});
});

describe("merging 'parserOptions'", () => {
Expand Down Expand Up @@ -8074,18 +8098,19 @@ describe("Linter with FlatConfigArray", () => {
/**
* fails due to: "ES Modules cannot be spied"
*/
it.skip("should have file path passed to it", () => {
it("should have file path passed to it", () => {
const code = "/* this is code */";
const parseSpy = sinon.spy(testParsers.stubParser, "parse");
const config = {
languageOptions: {
parser: testParsers.stubParser
}
};

linter.verify(code, config, filename, true);

sinon.assert.calledWithMatch(parseSpy, "", { filePath: filename });
expect(StubParser.parse).toBeCalledTimes(1);
const [arg0, arg1] = StubParser.parse.mock.calls[0];
expect(arg0).toBe(code);
expect(arg1.filePath).toBe(filename);
});

it("should not report an error when JSX code contains a spread operator and JSX is enabled", () => {
Expand Down Expand Up @@ -8389,6 +8414,10 @@ describe("Linter with FlatConfigArray", () => {
sourceType: "module"
}));
});

afterEach(() => {
StubParser.parse.mockClear()
})
});


Expand Down

0 comments on commit fe2e76f

Please sign in to comment.