-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reify git dependencies that have workspaces (#103)
* fix: reify git dependencies that have workspaces * chore: add tests for workspaces prepare When finding workspaces data in a package, pacote git fetcher should extract contents and run prepare scripts as part of that, this test makes sure that is happening. Co-authored-by: Ruy Adorno <[email protected]>
- Loading branch information
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ ghi.localhostssh = { | |
const remote = `git://localhost:${gitPort}/repo` | ||
const remoteHosted = `git://127.0.0.1:${gitPort}/repo` | ||
const submodsRemote = `git://localhost:${gitPort}/submodule-repo` | ||
const workspacesRemote = `git://localhost:${gitPort}/workspaces-repo` | ||
|
||
const GitFetcher = require('../lib/git.js') | ||
const t = require('tap') | ||
|
@@ -284,6 +285,36 @@ t.test('setup', { bail: true }, t => { | |
.then(() => git('commit', '-m', 'package')) | ||
}) | ||
|
||
t.test('create a repo with workspaces', t => { | ||
const repo = resolve(me, 'workspaces-repo') | ||
const wsfolder = resolve(me, 'workspaces-repo/a') | ||
const git = (...cmd) => spawnGit(cmd, { cwd: repo }) | ||
const write = (f, c) => fs.writeFileSync(`${repo}/${f}`, c) | ||
mkdirp.sync(wsfolder) | ||
return git('init') | ||
.then(() => git('config', 'user.name', 'pacotedev')) | ||
.then(() => git('config', 'user.email', '[email protected]')) | ||
.then(() => git('config', 'tag.gpgSign', 'false')) | ||
.then(() => git('config', 'commit.gpgSign', 'false')) | ||
.then(() => git('config', 'tag.forceSignAnnotated', 'false')) | ||
.then(() => write('package.json', JSON.stringify({ | ||
name: 'workspaces-root', | ||
version: '1.2.3', | ||
workspaces: ['a'], | ||
}))) | ||
.then(() => git('add', 'package.json')) | ||
.then(() => git('commit', '-m', 'package')) | ||
.then(() => write('a/package.json', JSON.stringify({ | ||
name: 'a', | ||
version: '1.0.0', | ||
scripts: { | ||
prepare: 'touch foo', | ||
}, | ||
}))) | ||
.then(() => git('add', 'a/package.json')) | ||
.then(() => git('commit', '-m', 'a/package.json')) | ||
}) | ||
|
||
t.test('hosted service', t => { | ||
const s = http.createServer((req, res) => { | ||
res.setHeader('connection', 'close') | ||
|
@@ -668,3 +699,15 @@ t.test('missing branch name throws pathspec error', async (t) => { | |
}, domain) | ||
} | ||
}) | ||
|
||
t.test('simple repo with workspaces', async t => { | ||
const ws = new GitFetcher(workspacesRemote, { cache }) | ||
const extract = resolve(me, 'extract-workspaces') | ||
await ws.extract(extract) | ||
// the file ./a/foo does not exist in the original repo | ||
// and should have been created during prepare phase | ||
t.ok( | ||
fs.statSync(me + '/extract-workspaces/a/foo'), | ||
'should run prepare phase when finding workspaces' | ||
) | ||
}) |