Skip to content

Commit d232dc5

Browse files
authored
File path formatting for checkIgnore running on Windows (#1084)
* Add windows test runner to Github Actions * Add support for `.win32.spec.ts` to find tests that need to be run on Windows
1 parent 9872f84 commit d232dc5

File tree

7 files changed

+62
-5
lines changed

7 files changed

+62
-5
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
build:
13+
build-ubuntu:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
@@ -29,3 +29,20 @@ jobs:
2929
GIT_AUTHOR_NAME: 'Simple Git Tests'
3030
GIT_AUTHOR_EMAIL: 'tests@simple-git.dev'
3131
run: yarn test
32+
33+
build-windows:
34+
runs-on: windows-latest
35+
steps:
36+
- uses: actions/checkout@v5
37+
- name: Use Node.js 24
38+
uses: actions/setup-node@v6
39+
with:
40+
node-version: 24
41+
cache: yarn
42+
- run: yarn install --immutable
43+
- run: yarn build
44+
- name: Test
45+
env:
46+
GIT_AUTHOR_NAME: 'Simple Git Tests'
47+
GIT_AUTHOR_EMAIL: 'tests@simple-git.dev'
48+
run: yarn test:win

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"clean:cache": "git clean -fxd .yarn node_modules packages simple-git",
1616
"lint": "biome check",
1717
"lint:fix": "biome check --write",
18-
"test": "yarn workspaces foreach -A run test"
18+
"test": "yarn workspaces foreach -A run test",
19+
"test:win": "yarn workspaces foreach -A run test:win"
1920
},
2021
"dependencies": {
2122
"@changesets/changelog-github": "^0.5.1",

packages/test-utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './src/wait';
88
export * from './src/setup/setup-conflicted';
99
export * from './src/setup/setup-files';
1010
export * from './src/setup/setup-init';
11+
export * from './src/setup/setup-ignored';

packages/test-utils/src/create-test-context.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { join } from 'path';
1+
import { tmpdir } from 'node:os';
2+
import { join } from 'node:path';
23
import { existsSync, mkdir, mkdtemp, realpathSync, writeFile, WriteFileOptions } from 'fs';
4+
35
import { simpleGit, SimpleGit } from 'simple-git';
46

57
export interface SimpleGitTestContext {
@@ -36,7 +38,7 @@ const io = {
3638
},
3739
mkdtemp(): Promise<string> {
3840
return new Promise((done, fail) => {
39-
mkdtemp((process.env.TMPDIR || '/tmp/') + 'simple-git-test-', (err, path) => {
41+
mkdtemp(join(process.env.TMPDIR || tmpdir(), 'simple-git-test-'), (err, path) => {
4042
err ? fail(err) : done(path);
4143
});
4244
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { SimpleGitTestContext } from '../create-test-context';
2+
3+
export async function setUpIgnored({ git, file }: SimpleGitTestContext, paths: string[] = [], filename = '.gitignore') {
4+
await file(filename, paths.join('\n') + '\n');
5+
6+
await git.add(filename);
7+
await git.commit(`setUpIgnored: ${filename}`);
8+
}
9+

simple-git/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"build:defs": "tsc -p tsconfig.release.json --outDir dist && cp -r typings dist",
6464
"build:pkg": "node scripts/package-json.js",
6565
"prepublishOnly": "yarn build:pkg",
66-
"test": "jest --coverage"
66+
"test": "jest --coverage",
67+
"test:win": "jest '\\.win32.spec.ts$'"
6768
},
6869
"publish": {
6970
"main": "dist/cjs/index.js",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createTestContext, setUpIgnored, setUpInit, SimpleGitTestContext } from '@simple-git/test-utils';
2+
3+
describe('checkIgnore', () => {
4+
5+
let context: SimpleGitTestContext;
6+
7+
beforeEach(async () => (context = await createTestContext()));
8+
beforeEach(async () => {
9+
await setUpInit(context);
10+
await setUpIgnored(context, ['ignored', 'partially/untracked']);
11+
});
12+
13+
it('detects ignored files', async () => {
14+
const actual = await context.git.checkIgnore([
15+
'ignored/anything',
16+
'tracked/anything',
17+
'partially/tracked',
18+
'partially/untracked/file',
19+
]);
20+
21+
expect(actual).toEqual([
22+
'ignored/anything',
23+
'partially/untracked/file',
24+
]);
25+
});
26+
});

0 commit comments

Comments
 (0)