Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test in windows, remove coverage map, test cleanup #137

Merged
merged 4 commits into from Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci-release.yml
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down
1 change: 0 additions & 1 deletion map.js

This file was deleted.

4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -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/**"
Expand Down Expand Up @@ -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"
}
}
44 changes: 32 additions & 12 deletions test/find.js
@@ -1,32 +1,30 @@
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 => {
const root = t.testdir({
'.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 => {
const root = t.testdir({
'.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 => {
const root = t.testdir({
'.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 => {
Expand All @@ -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))
}
})
24 changes: 16 additions & 8 deletions 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
Expand Down