Skip to content

Commit

Permalink
Strip unit tests to most essential stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 15, 2024
1 parent 1095eb3 commit 1cc1ba9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 146 deletions.
23 changes: 0 additions & 23 deletions tests/postprocess.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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);
});
});
});
123 changes: 0 additions & 123 deletions tests/preprocess.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -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);
});
});
});

0 comments on commit 1cc1ba9

Please sign in to comment.