Skip to content

Commit

Permalink
feat: Move to separate versioning for records (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjylewis authored Aug 17, 2019
1 parent 6e3071c commit 79043fc
Show file tree
Hide file tree
Showing 34 changed files with 118 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CHANGELOG.md
__tests__/integration/fixtures/invalid-record/.esplint.rec.json
__tests__/integration/fixtures/extra-semi/index.js
__tests__/integration/fixtures/suppressed-extra-semi/index.js
__tests__/integration/fixtures/suppressed-extra-semi/index.js
__tests__/integration/fixtures/merge-conflict/.esplint.rec.json
34 changes: 25 additions & 9 deletions __tests__/integration/engine/run.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const log = require("../../../lib/log");
const stripAnsi = require("strip-ansi");
const { version } = require("../../../package.json");
const { fixtureInit } = require("../util");
jest.mock("../../../package.json", () => ({ version: "1.0.0" }));

const { setup, readRecord, onBeforeAll, onAfterEach, onAfterAll } = fixtureInit(
"engine.run"
Expand Down Expand Up @@ -289,7 +289,7 @@ describe("engine.run", () => {
);

it(
"should throw error if record version is newer and record file changes",
"should throw error if record version is newer than current version",
setup("new-version-decrease-warning", () => {
const { run } = require("../../../lib/engine");

Expand All @@ -298,35 +298,51 @@ describe("engine.run", () => {
expect("It should never get here").toBe(false);
} catch (e) {
expect(stripAnsi(e.message)).toEqual(
`✖ You are using an older version of esplint (${version}) than what was used to create .esplint.rec.json (1000.0.0).\nMake sure to upgrade so you're on the same version.`
`✖ You are using an older "record version" of esplint (1) than what was used to create .esplint.rec.json (2).\nMake sure to upgrade esplint so you're on the same "record version" (or higher).`
);
}
})
);

it(
"should succeed even if record version is newer if record file does NOT change",
setup("new-version-no-change", ({ fixturePath }) => {
"should succeed and update to new record version if record version is older than current version",
setup("old-version", ({ fixturePath }) => {
const { run } = require("../../../lib/engine");
const { results, hasError } = run({}, ["."]);
expect(hasError).toEqual(false);
expect(results).toHaveLength(0);

const record = readRecord(fixturePath);
expect(record.version).toEqual("1000.0.0");
expect(record.recordVersion).toEqual(1);
})
);

it(
"should succeed and update if record version is older regardless if there's no change",
setup("old-version-no-change", ({ fixturePath }) => {
"should throw error if record version is uses legacy version less than 0.4.1",
setup("legacy-version-not-acceptable", () => {
const { run } = require("../../../lib/engine");

try {
run({}, ["."]);
expect("It should never get here").toBe(false);
} catch (e) {
expect(stripAnsi(e.message)).toEqual(
`✖ Cannot determine the version of your record file or the version is too out-of-date.\nPlease use the --overwrite flag to re-generate your record file.`
);
}
})
);

it(
"should succeed and update to new record version if record version is legacy but >= 0.4.1",
setup("legacy-version-acceptable", ({ fixturePath }) => {
const { run } = require("../../../lib/engine");
const { results, hasError } = run({}, ["."]);
expect(hasError).toEqual(false);
expect(results).toHaveLength(0);

const record = readRecord(fixturePath);
expect(record.version).not.toEqual("0.0.0");
expect(record.recordVersion).toEqual(1);
})
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.3.0",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.3.0",
"recordVersion": 1,
"hash": "119be9453c3998b726c7787fe9337957df1f7315",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
"no-console": 2,
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.0",
"version": "0.4.1",
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1000.0.0",
"version": "0.4.0",
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
<<<<<<< HEAD
Expand All @@ -22,4 +22,4 @@
"no-console": 1
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/fixtures/new-file/.esplint.rec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1000.0.0",
"recordVersion": 2,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "no going to match",
"files": {
"index.js": {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/fixtures/no-rules/.esplint.rec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "989db2448f309bfdd99b513f37c84b8f5794d2b5",
"files": {
"index.js": {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "989db2448f309bfdd99b513f37c84b8f5794d2b5",
"files": {
"index.js": {}
Expand Down
5 changes: 5 additions & 0 deletions __tests__/integration/fixtures/old-version/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
"no-console": "warn"
}
};
9 changes: 9 additions & 0 deletions __tests__/integration/fixtures/old-version/.esplint.rec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recordVersion": 0,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"index.js": {
"no-console": 1
}
}
}
4 changes: 4 additions & 0 deletions __tests__/integration/fixtures/old-version/.esplintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
surfaceArea: ["."],
rules: ["no-console"]
};
1 change: 1 addition & 0 deletions __tests__/integration/fixtures/old-version/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-1",
"recordVersion": 1,
"hash": "cc3bc4038476f82524667d6bcd834dad8d64d572",
"files": {
"a.js": {
Expand Down
7 changes: 5 additions & 2 deletions __tests__/record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ jest.mock("../package.json", () => ({ version: "1.0.0" }));

describe("createRecord", () => {
it("attaches current version", () => {
const { version } = createRecord({ config: { rules: [] }, files: {} });
expect(version).toEqual("1.0.0");
const { recordVersion } = createRecord({
config: { rules: [] },
files: {}
});
expect(recordVersion).toEqual(1);
});

it("sorts files", () => {
Expand Down
5 changes: 1 addition & 4 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
isRecordEmpty,
getRecord,
writeRecord,
compareRecords,
readRecord
} = require("./record");
const {
Expand Down Expand Up @@ -64,9 +63,7 @@ function run(options, files) {
files: combinedFileSet
});

if (compareRecords(oldRecord, newRecord).shouldWrite) {
writeRecord(newRecord);
}
writeRecord(newRecord);
}

return { results, hasError };
Expand Down
Loading

0 comments on commit 79043fc

Please sign in to comment.