Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tightly-coupled dependency on Stylelint's internal module `lib/ut…
…ils/getOsEol` (#66) This change aims to make changes easier by removing the dependency on an internal module. Summary: - Change the `os.EOL` property by the before/all hooks instead of mocking. - Add a file for `setupFilesAfterEnv`. - Delay requiring `stylelint` in `getTestRule()`. See also: - https://github.com/stylelint/stylelint/blob/0dbed54626e87786c2ef2e4ccd4c27d04c8a6918/lib/utils/getOsEol.js - https://jestjs.io/docs/configuration/#setupfilesafterenv-array
- Loading branch information
1 parent
a33df6f
commit 61ab750
Showing
7 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
exports[`should contain expected keys 1`] = ` | ||
[ | ||
"setupFiles", | ||
"setupFilesAfterEnv", | ||
"testEnvironment", | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
'use strict'; | ||
|
||
// Mock should be before stylelint required. Even if it's required inside other modules | ||
jest.mock('stylelint/lib/utils/getOsEol', () => () => '\n'); | ||
|
||
const getTestRule = require('./getTestRule'); | ||
|
||
global.testRule = getTestRule(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters