Skip to content

Commit

Permalink
chore: Add test case for retrieving repository URL
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallku committed Jun 26, 2024
1 parent cfbb361 commit fa827d2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/repository.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { exec } = require('node:child_process')
const t = require('tap')
const { setup, child, isChild } = require('./fixtures/setup')

Expand Down Expand Up @@ -35,3 +36,49 @@ t.test('license', async (t) => {
}
t.has(data, wanted)
})

const getRemoteURL = () => new Promise((res, rej) => {
exec('git config --get remote.origin.url', (err, stdout) => {
if (err) {
rej(err)
} else {
res(stdout.trim())
}
})
})

t.test('parse repository from git config', async (t) => {
const { data } = await setup(t, __filename, {
inputs: [
'the-name', // package name
'', // version
'', // description
'', // entry point
'', // test
'', // git repo
'', // keywords
'', // author
'', // license
'yes', // about to write
],
})
const remoteURL = await getRemoteURL()

const wanted = {
name: 'the-name',
version: '1.0.0',
description: '',
scripts: { test: 'echo "Error: no test specified" && exit 1' },
author: '',
main: 'index.js',
}

if (remoteURL) {
wanted.repository = {
type: 'git',
url: `git+${remoteURL}`,
}
}

t.has(data, wanted)

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 16.14.0

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 16.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.0.0

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 22.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 16.14.0

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 16.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.0.0

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

should contain all provided fields

Check failure on line 83 in test/repository.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 22.x

should contain all provided fields
})

0 comments on commit fa827d2

Please sign in to comment.