From 1d9b5499bd450188ad136c8fb3d763eacdf70608 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 5 Jun 2023 13:37:38 -0700 Subject: [PATCH 1/4] chore: windows ci --- .github/workflows/ci-release.yml | 3 +++ .github/workflows/ci.yml | 3 +++ package.json | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index fea9ae7..88e7905 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -113,6 +113,9 @@ jobs: - name: macOS os: macos-latest shell: bash + - name: Windows + os: windows-latest + shell: cmd node-version: - 14.17.0 - 14.x diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7afbdb6..9cc149d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,9 @@ jobs: - name: macOS os: macos-latest shell: bash + - name: Windows + os: windows-latest + shell: cmd node-version: - 14.17.0 - 14.x diff --git a/package.json b/package.json index 97d9366..d3bc5b2 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "template-oss-apply": "template-oss-apply --force" }, "tap": { - "check-coverage": true, + "timeout": 600, "coverage-map": "map.js", "nyc-arg": [ "--exclude", @@ -52,7 +52,6 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "windowsCI": false, "version": "4.15.1" } } From 338446f36584ba1493fb88ecd2ba8a9cb846167f Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 5 Jun 2023 14:03:41 -0700 Subject: [PATCH 2/4] chore: remove coverage map --- map.js | 1 - package.json | 1 - 2 files changed, 2 deletions(-) delete mode 100644 map.js diff --git a/map.js b/map.js deleted file mode 100644 index a08c787..0000000 --- a/map.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = test => test.replace(/^test/, 'lib') diff --git a/package.json b/package.json index d3bc5b2..73c255d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ }, "tap": { "timeout": 600, - "coverage-map": "map.js", "nyc-arg": [ "--exclude", "tap-snapshots/**" From 1759d1cb7dfb32783eaeaf243de6536a62694642 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 5 Jun 2023 14:07:43 -0700 Subject: [PATCH 3/4] chore: fix opts test if test env has askpass or ssh command --- test/opts.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/opts.js b/test/opts.js index 32951ab..6d21c84 100644 --- a/test/opts.js +++ b/test/opts.js @@ -1,14 +1,22 @@ const t = require('tap') const gitOpts = require('../lib/opts.js') -const gitEnv = { - GIT_ASKPASS: 'echo', - GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new', -} -t.match(gitOpts().env, gitEnv, 'got the git defaults we want') - -t.equal(gitOpts().shell, false, 'shell defaults to false') -t.equal(gitOpts({ shell: '/bin/bash' }).shell, false, 'shell cannot be overridden') +t.test('defaults', t => { + const { GIT_ASKPASS, GIT_SSH_COMMAND } = process.env + t.teardown(() => { + process.env.GIT_ASKPASS = GIT_ASKPASS + process.env.GIT_SSH_COMMAND = GIT_SSH_COMMAND + }) + delete process.env.GIT_ASKPASS + delete process.env.GIT_SSH_COMMAND + t.match(gitOpts().env, { + GIT_ASKPASS: 'echo', + GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new', + }, 'got the git defaults we want') + t.equal(gitOpts().shell, false, 'shell defaults to false') + t.equal(gitOpts({ shell: '/bin/bash' }).shell, false, 'shell cannot be overridden') + t.end() +}) t.test('does not override', t => { const { GIT_ASKPASS, GIT_SSH_COMMAND } = process.env From 05a701d541375f25de9da2aace7d62c9775096c9 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 5 Jun 2023 14:47:30 -0700 Subject: [PATCH 4/4] fix: dont default `find` `root` option to anything This ensures that it will only short circuit if a valid path is passed in. This commit also adds one more mocked test to ensure that the system root path is always checked as the last path and no path is checked twice. --- lib/find.js | 4 ++-- test/find.js | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/find.js b/lib/find.js index e520ce8..34bd310 100644 --- a/lib/find.js +++ b/lib/find.js @@ -1,7 +1,7 @@ const is = require('./is.js') -const { dirname, sep } = require('path') +const { dirname } = require('path') -module.exports = async ({ cwd = process.cwd(), root = sep } = {}) => { +module.exports = async ({ cwd = process.cwd(), root } = {}) => { while (true) { if (await is({ cwd })) { return cwd diff --git a/test/find.js b/test/find.js index 3101912..1951cc4 100644 --- a/test/find.js +++ b/test/find.js @@ -1,5 +1,6 @@ const t = require('tap') -const { join } = require('path') +const { join, parse } = require('path') +const { tmpdir } = require('os') const find = require('../lib/find.js') t.test('find the git dir many folders up', t => { @@ -7,8 +8,7 @@ t.test('find the git dir many folders up', t => { '.git': { index: 'hello' }, a: { b: { c: { d: { e: {} } } } }, }) - const path = `${root}/a/b/c/d/e` - return t.resolveMatch(find({ cwd: path }), root) + return t.resolveMatch(find({ cwd: join(root, 'a/b/c/d/e') }), root) }) t.test('stop before root dir', t => { @@ -16,8 +16,7 @@ t.test('stop before root dir', t => { '.git': { index: 'hello' }, a: { b: { c: { d: { e: {} } } } }, }) - const path = `${root}/a/b/c/d/e` - return t.resolveMatch(find({ cwd: path, root: join(root, 'a') }), null) + return t.resolveMatch(find({ cwd: join(root, 'a/b/c/d/e'), root: join(root, 'a') }), null) }) t.test('stop at root dir', t => { @@ -25,8 +24,7 @@ t.test('stop at root dir', t => { '.git': { index: 'hello' }, a: { b: { c: { d: { e: {} } } } }, }) - const path = `${root}/a/b/c/d/e` - return t.resolveMatch(find({ cwd: path, root }), root) + return t.resolveMatch(find({ cwd: join(root, 'a/b/c/d/e'), root }), root) }) t.test('find the git dir at current level', t => { @@ -38,13 +36,35 @@ t.test('find the git dir at current level', t => { t.test('no git dir to find', t => { // this will fail if your tmpdir is in a git repo, I suppose - const path = require('os').tmpdir() - return t.resolveMatch(find({ cwd: path }), null) + return t.resolveMatch(find({ cwd: tmpdir() }), null) }) t.test('default to cwd', t => { - // this will fail if your tmpdir is in a git repo, I suppose - const path = require('os').tmpdir() - process.chdir(path) + const dir = process.cwd() + t.teardown(() => process.chdir(dir)) + process.chdir(tmpdir()) return t.resolveMatch(find(), null) }) + +t.test('mock is', async t => { + const cwd = tmpdir() + const { root } = parse(cwd) + + const mockFind = async (t, opts) => { + const seen = [] + const mocked = t.mock('../lib/find.js', { + '../lib/is.js': async (o) => { + seen.push(o.cwd) + return false + }, + }) + const res = await mocked({ cwd, ...opts }) + t.strictSame(res, null) + t.strictSame(seen, [...new Set(seen)], 'no directory checked more than once') + t.equal(seen[seen.length - 1], root, 'last dir is root') + } + + for (const tCase of [undefined, { root }, { root: 1 }]) { + await t.test(`root: ${JSON.stringify(tCase)}`, t => mockFind(t, tCase)) + } +})