diff --git a/tests/postprocess.js b/tests/postprocess.js index 2238005..7e262e3 100644 --- a/tests/postprocess.js +++ b/tests/postprocess.js @@ -1,5 +1,3 @@ -const fs = require("fs"); - const assert = require("chai").assert; const { preprocessJs: pre } = require("../lib/preprocess.js"); const post = require("../lib/postprocess.js"); @@ -17,25 +15,4 @@ describe("postprocess", () => { post([[]], name); assert.isUndefined(cache.get(name)); }); - - const mapFiles = [ - "one-liner", - "common", - "each-do", - "multi-line", - "multiple-erb-in-one-line", - ]; - mapFiles.forEach((name) => { - it(`correctly maps location from offset map on ${name}.js`, () => { - const filename = `tests/fixtures/${name}.js`; - const text = fs.readFileSync(filename, "utf-8"); - pre(text, filename); - - const esLintMessages = require(`../tests/fixtures/${name}.messages.js`); - - const finalMessages = post([esLintMessages], filename); - const expectedMessages = require(`../tests/fixtures/${name}.expected.messages.js`); - assert.deepEqual(expectedMessages, finalMessages); - }); - }); }); diff --git a/tests/preprocess.js b/tests/preprocess.js index ed048ad..4653e68 100644 --- a/tests/preprocess.js +++ b/tests/preprocess.js @@ -1,8 +1,5 @@ -const fs = require("fs"); - const assert = require("chai").assert; const { preprocessJs: p } = require("../lib/preprocess.js"); -const cache = require("../lib/cache.js"); describe("preprocess", () => { it("does not crash", () => { @@ -23,124 +20,4 @@ describe("preprocess", () => { const res = p("Hello, world!")[0]; assert.equal(res, "Hello, world!"); }); - - const replaceStringFiles = [ - "one-liner", - "common", - "each-do", - "multi-line", - "multiple-erb-in-one-line", - ]; - replaceStringFiles.forEach((name) => { - it(`replaces ruby with dummy string in "${name}.js"`, () => { - const text = fs.readFileSync(`tests/fixtures/${name}.js`, "utf-8"); - const textLintableExpected = fs.readFileSync(`tests/fixtures/${name}.pre.js`, "utf-8"); - - const textLintable = p(text)[0]; - assert.equal(textLintable, textLintableExpected); - }); - }); - - const offsets = [ - { - name: "one-liner", - expected: { - lineOffsetLookup: new Map([ - [1, new Map([ - [45, { lineOffset: 0, columnOffset: -32 }], - ])], - ]), - offsetLookup: new Map([ - [45, { lineOffset: 0, columnOffset: -32 }], - ]), - }, - }, - { - name: "multi-line", - expected: { - lineOffsetLookup: new Map([ - [2, new Map([ - [64, { lineOffset: 2, columnOffset: -7 }], - ])], - ]), - offsetLookup: new Map([ - [64, { lineOffset: 2, columnOffset: -7 }], - ]), - }, - }, - { - name: "common", - expected: { - lineOffsetLookup: new Map([ - [1, new Map([ - [50, { lineOffset: 0, columnOffset: -26 }], - ])], - [3, new Map([ - [155, { lineOffset: 1, columnOffset: -13 }], - ])], - [9, new Map([ - [268, { lineOffset: 1, columnOffset: -18 }], - ])], - [11, new Map([ - [349, { lineOffset: 1, columnOffset: -32 }], - ])], - ]), - offsetLookup: new Map([ - [50, { lineOffset: 0, columnOffset: -26 }], - [155, { lineOffset: 1, columnOffset: -13 }], - [268, { lineOffset: 1, columnOffset: -18 }], - [349, { lineOffset: 1, columnOffset: -32 }], - ]), - }, - }, - { - name: "each-do", - expected: { - lineOffsetLookup: new Map([ - [1, new Map([ - [41, { lineOffset: 0, columnOffset: -17 }], - ])], - [2, new Map([ - [96, { lineOffset: 0, columnOffset: -33 }], - ])], - [3, new Map([ - [154, { lineOffset: 0, columnOffset: -32 }], - ])], - ]), - offsetLookup: new Map([ - [41, { lineOffset: 0, columnOffset: -17 }], - [96, { lineOffset: 0, columnOffset: -33 }], - [154, { lineOffset: 0, columnOffset: -32 }], - ]), - }, - }, - { - // This tests that column offsets are correctly calculated for multiple - // ERB tags on the same line. - name: "multiple-erb-in-one-line", - expected: { - lineOffsetLookup: new Map([ - [1, new Map([ - [61, { lineOffset: 0, columnOffset: -17 }], - [126, { lineOffset: 0, columnOffset: -45 }], - [188, { lineOffset: 0, columnOffset: -77 }], - ])], - ]), - offsetLookup: new Map([ - [61, { lineOffset: 0, columnOffset: -17 }], - [126, { lineOffset: 0, columnOffset: -45 }], - [188, { lineOffset: 0, columnOffset: -77 }], - ]), - }, - }, - ]; - offsets.forEach(({ name, expected }) => { - it(`correctly constructs offset map for "${name}.js`, () => { - const text = fs.readFileSync(`tests/fixtures/${name}.js`, "utf-8"); - p(text, name); - const offsetMap = cache.get(name).offsetMap; - assert.deepEqual(offsetMap.lineOffsetLookup, expected.lineOffsetLookup); - assert.deepEqual(offsetMap.offsetLookup, expected.offsetLookup); - }); - }); });