Skip to content

Commit

Permalink
chore: fix tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 23, 2024
1 parent c61b72f commit 0641788
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
14 changes: 1 addition & 13 deletions tests/lib/new-rule-format/new-rule-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,11 @@

const jscodeshift = require("jscodeshift");
const fs = require("fs");
const os = require("os");
const path = require("path");
const assert = require("assert");

const newRuleFormatTransform = require("../../../lib/new-rule-format/new-rule-format");

/**
* Returns a new string with all the EOL markers from the string passed in
* replaced with the Operating System specific EOL marker.
* Useful for guaranteeing two transform outputs have the same EOL marker format.
* @param {string} input the string which will have its EOL markers replaced
* @returns {string} a new string with all EOL markers replaced
* @private
*/
function normalizeLineEndngs(input) {
return input.replace(/(\r\n|\n|\r)/gmu, os.EOL);
}
const { normalizeLineEndngs } = require("../../utils");

/**
* Run a transform against a fixture file and compare results with expected output.
Expand Down
13 changes: 7 additions & 6 deletions tests/lib/v9-migration/v9-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const path = require("path");
const { applyTransform } = require("@hypermod/utils");
const assert = require("assert");
const sinon = require("sinon");
const { normalizeLineEndngs } = require("../../utils");
const v9MigrationTransform = require("../../../lib/v9-migration/v9-migration");

describe("v9 migration transform", () => {
Expand All @@ -25,13 +26,13 @@ describe("v9 migration transform", () => {
);

assert.strictEqual(
result,
`
normalizeLineEndngs(result),
normalizeLineEndngs(`
const sourceCode = context.sourceCode ?? context.getSourceCode();
const cwd = context.cwd ?? context.getCwd();
const filename = context.filename ?? context.getFilename();
const physicalFilename = context.physicalFilename ?? context.getPhysicalFilename();
`.trim()
`.trim())
);
});

Expand All @@ -50,16 +51,16 @@ describe("v9 migration transform", () => {
);

assert.strictEqual(
result,
`
normalizeLineEndngs(result),
normalizeLineEndngs(`
const sourceCode = context.sourceCode.getText();
const sourceLines = context.sourceCode.getLines();
const allComments = context.sourceCode.getAllComments();
const nodeByRangeIndex = context.sourceCode.getNodeByRangeIndex();
const commentsBefore = context.sourceCode.getCommentsBefore(nodeOrToken);
const commentsAfter = context.sourceCode.getCommentsAfter(nodeOrToken);
const commentsInside = context.sourceCode.getCommentsInside(nodeOrToken);
`.trim()
`.trim())
);
});

Expand Down
19 changes: 19 additions & 0 deletions tests/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";

const os = require("os");

/**
* Returns a new string with all the EOL markers from the string passed in
* replaced with the Operating System specific EOL marker.
* Useful for guaranteeing two transform outputs have the same EOL marker format.
* @param {string} input the string which will have its EOL markers replaced
* @returns {string} a new string with all EOL markers replaced
* @private
*/
function normalizeLineEndngs(input) {
return input.replace(/(\r\n|\n|\r)/gmu, os.EOL);
}

module.exports = {
normalizeLineEndngs
};

Check failure on line 19 in tests/utils/index.js

View workflow job for this annotation

GitHub Actions / Lint

Newline required at end of file but not found

0 comments on commit 0641788

Please sign in to comment.