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/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/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 97d9366..73c255d 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "template-oss-apply": "template-oss-apply --force" }, "tap": { - "check-coverage": true, - "coverage-map": "map.js", + "timeout": 600, "nyc-arg": [ "--exclude", "tap-snapshots/**" @@ -52,7 +51,6 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "windowsCI": false, "version": "4.15.1" } } 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)) + } +}) 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