-
-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adjust tests for Windows compatibility
- v15.3.0
- v15.2.11
- v15.2.10
- v15.2.9
- v15.2.8
- v15.2.7
- v15.2.6
- v15.2.5
- v15.2.4
- v15.2.3
- v15.2.2
- v15.2.1
- v15.2.0
- v15.1.0
- v15.0.2
- v15.0.1
- v15.0.0
- v14.0.1
- v14.0.0
- v13.3.0
- v13.2.3
- v13.2.2
- v13.2.1
- v13.2.0
- v13.1.2
- v13.1.1
- v13.1.0
- v13.0.4
- v13.0.3
- v13.0.2
- v13.0.1
- v13.0.0
- v12.5.0
- v12.4.3
- v12.4.2
- v12.4.1
- v12.4.0
- v12.3.8
- v12.3.7
- v12.3.6
- v12.3.5
- v12.3.4
- v12.3.3
- v12.3.2
- v12.3.1
- v12.3.0
- v12.2.2
- v12.2.1
- v12.2.0
- v12.1.7
- v12.1.6
- v12.1.5
- v12.1.4
- v12.1.3
- v12.1.2
- v12.1.1
- v12.1.0
- v12.0.3
- v12.0.2
- v12.0.1
- v12.0.0
Showing
4 changed files
with
18 additions
and
19 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import execGitBase from '../lib/execGit' | |
import lintStaged from '../lib/index' | ||
import { replaceSerializer } from './utils/replaceSerializer' | ||
import { createTempDir } from './utils/tempDir' | ||
import { isWindowsActions, normalizeWindowsNewlines } from './utils/crossPlatform' | ||
|
||
jest.setTimeout(20000) | ||
|
||
|
@@ -36,7 +37,7 @@ let cwd | |
// Get file content, coercing Windows `\r\n` newlines to `\n` | ||
const readFile = async (filename, dir = cwd) => { | ||
const file = await fs.readFile(path.resolve(dir, filename), { encoding: 'utf-8' }) | ||
return file.replace(/(\r\n|\r|\n)/gm, '\n') | ||
return normalizeWindowsNewlines(file) | ||
} | ||
|
||
// Append to file, creating if it doesn't exist | ||
|
@@ -97,6 +98,7 @@ describe('lint-staged', () => { | |
await execGit('init') | ||
await execGit(['config', 'user.name', '"test"']) | ||
await execGit(['config', 'user.email', '"[email protected]"']) | ||
if (isWindowsActions()) await execGit(['config', 'core.autocrlf', 'input']) | ||
await appendFile('README.md', '# Test\n') | ||
await execGit(['add', 'README.md']) | ||
await execGit(['commit', '-m initial commit']) | ||
|
@@ -224,11 +226,12 @@ describe('lint-staged', () => { | |
await execGit(['add', 'test.js']) | ||
|
||
// Edit pretty file but do not stage changes | ||
const appended = '\nconsole.log("test");\n' | ||
const appended = `\nconsole.log("test");\n` | ||
await appendFile('test.js', appended) | ||
|
||
// Run lint-staged with `prettier --list-different` and commit pretty file | ||
await gitCommit({ config: { '*.js': 'prettier --list-different' } }) | ||
|
||
expect(console.printHistory()).toMatchInlineSnapshot(` | ||
" | ||
LOG [STARTED] Preparing... | ||
|
@@ -261,7 +264,8 @@ describe('lint-staged', () => { | |
const status = await execGit(['status']) | ||
expect(status).toMatch('modified: test.js') | ||
expect(status).toMatch('no changes added to commit') | ||
expect(await readFile('test.js')).toEqual(testJsFilePretty + appended) | ||
/** @todo `git` in GitHub Windows runners seem to add `\r\n` newlines in this case. */ | ||
expect(normalizeWindowsNewlines(await readFile('test.js'))).toEqual(testJsFilePretty + appended) | ||
}) | ||
|
||
it('Should commit partial change from partially staged file when no errors from linter and linter modifies file', async () => { | ||
|
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,8 @@ | ||
/** Whether the current environment is a GitHub Actions runner under Windows */ | ||
export const isWindowsActions = () => { | ||
const { GITHUB_ACTIONS, RUNNER_OS } = process.env | ||
return GITHUB_ACTIONS === 'true' && RUNNER_OS === 'Windows' | ||
} | ||
|
||
/** Replace Windows `\r\n` newlines with `\n` */ | ||
export const normalizeWindowsNewlines = (input) => input.replace(/(\r\n|\r|\n)/gm, '\n') |
This file was deleted.
Oops, something went wrong.