Skip to content

Commit

Permalink
Revert "Move os.EOL into testRule() and remove no longer needed `…
Browse files Browse the repository at this point in the history
…jest-setup-after-env.js`"

This reverts commit ebe4650.
  • Loading branch information
ybiquitous committed Jul 26, 2023
1 parent ebe4650 commit 3310063
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions __tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`should contain expected keys 1`] = `
[
"setupFiles",
"setupFilesAfterEnv",
"testEnvironment",
]
`;
12 changes: 0 additions & 12 deletions getTestRule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const os = require('os');
const util = require('util');

/**
Expand All @@ -14,20 +13,9 @@ module.exports = function getTestRule(options = {}) {
/** @type {import('stylelint').lint} */
let lint;

const eolDescriptor = Object.getOwnPropertyDescriptor(os, 'EOL');

if (!eolDescriptor) throw new TypeError('`os` must have an `EOL` property');

beforeAll(() => {
// eslint-disable-next-line n/no-unpublished-require -- Avoid auto-install of `stylelint` peer dependency.
lint = require('stylelint').lint;

// NOTE: `jest.replaceProperty()` is unavailable for a read-only property.
Object.defineProperty(os, 'EOL', { ...eolDescriptor, value: '\n' });
});

afterAll(() => {
Object.defineProperty(os, 'EOL', eolDescriptor);
});

describe(`${schema.ruleName}`, () => {
Expand Down
1 change: 1 addition & 0 deletions jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

module.exports = {
setupFiles: [require.resolve('./jest-setup.js')],
setupFilesAfterEnv: [require.resolve('./jest-setup-after-env.js')],
testEnvironment: 'node',
};
18 changes: 18 additions & 0 deletions jest-setup-after-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const os = require('os');

const eolDescriptor = Object.getOwnPropertyDescriptor(os, 'EOL');

if (!eolDescriptor) {
throw new TypeError('`os` must have an `EOL` property');
}

beforeAll(() => {
// NOTE: `jest.replaceProperty()` is unavailable for a read-only property.
Object.defineProperty(os, 'EOL', { ...eolDescriptor, value: '\n' });
});

afterAll(() => {
Object.defineProperty(os, 'EOL', eolDescriptor);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"getTestRule.js",
"jest-preset.js",
"jest-setup.js",
"jest-setup-after-env.js",
"index.d.ts"
],
"scripts": {
Expand Down

0 comments on commit 3310063

Please sign in to comment.