Skip to content

Commit

Permalink
chore: don't use touch on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
s-h-a-d-o-w authored and iiroj committed Mar 16, 2022
1 parent 531275c commit 517235d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/integration.test.js
Expand Up @@ -29,7 +29,7 @@ import lintStaged from '../lib/index'

import { replaceSerializer } from './utils/replaceSerializer'
import { createTempDir } from './utils/tempDir'
import { isWindowsActions, normalizeWindowsNewlines } from './utils/crossPlatform'
import { isWindows, isWindowsActions, normalizeWindowsNewlines } from './utils/crossPlatform'

jest.setTimeout(20000)
jest.retryTimes(2)
Expand Down Expand Up @@ -97,7 +97,7 @@ const appendFile = async (filename, content, dir = cwd) => {
const writeFile = async (filename, content, dir = cwd) => {
const filepath = path.isAbsolute(filename) ? filename : path.join(dir, filename)
await ensureDir(filepath)
fs.writeFile(filepath, content)
await fs.writeFile(filepath, content)
}

// Wrap execGit to always pass `gitOps`
Expand Down Expand Up @@ -449,9 +449,10 @@ describe('lint-staged', () => {
// The task creates a git lock file and runs `git add` to simulate failure
await expect(
gitCommit({
shell: isWindows,
config: {
'*.js': (files) => [
`touch ${cwd}/.git/index.lock`,
`${isWindows ? 'type nul >' : 'touch'} ${cwd}/.git/index.lock`,
`prettier --write ${files.join(' ')}`,
`git add ${files.join(' ')}`,
],
Expand Down
4 changes: 4 additions & 0 deletions test/utils/crossPlatform.js
@@ -1,3 +1,7 @@
import os from 'os'

export const isWindows = os.platform() === 'win32'

/** Whether the current environment is a GitHub Actions runner under Windows */
export const isWindowsActions = () => {
const { GITHUB_ACTIONS, RUNNER_OS } = process.env
Expand Down

0 comments on commit 517235d

Please sign in to comment.