Skip to content

Commit 517235d

Browse files
s-h-a-d-o-wiiroj
authored andcommitted
chore: don't use touch on windows
1 parent 531275c commit 517235d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

test/integration.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import lintStaged from '../lib/index'
2929

3030
import { replaceSerializer } from './utils/replaceSerializer'
3131
import { createTempDir } from './utils/tempDir'
32-
import { isWindowsActions, normalizeWindowsNewlines } from './utils/crossPlatform'
32+
import { isWindows, isWindowsActions, normalizeWindowsNewlines } from './utils/crossPlatform'
3333

3434
jest.setTimeout(20000)
3535
jest.retryTimes(2)
@@ -97,7 +97,7 @@ const appendFile = async (filename, content, dir = cwd) => {
9797
const writeFile = async (filename, content, dir = cwd) => {
9898
const filepath = path.isAbsolute(filename) ? filename : path.join(dir, filename)
9999
await ensureDir(filepath)
100-
fs.writeFile(filepath, content)
100+
await fs.writeFile(filepath, content)
101101
}
102102

103103
// Wrap execGit to always pass `gitOps`
@@ -449,9 +449,10 @@ describe('lint-staged', () => {
449449
// The task creates a git lock file and runs `git add` to simulate failure
450450
await expect(
451451
gitCommit({
452+
shell: isWindows,
452453
config: {
453454
'*.js': (files) => [
454-
`touch ${cwd}/.git/index.lock`,
455+
`${isWindows ? 'type nul >' : 'touch'} ${cwd}/.git/index.lock`,
455456
`prettier --write ${files.join(' ')}`,
456457
`git add ${files.join(' ')}`,
457458
],

test/utils/crossPlatform.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os from 'os'
2+
3+
export const isWindows = os.platform() === 'win32'
4+
15
/** Whether the current environment is a GitHub Actions runner under Windows */
26
export const isWindowsActions = () => {
37
const { GITHUB_ACTIONS, RUNNER_OS } = process.env

0 commit comments

Comments
 (0)