Skip to content

Commit 9c7f697

Browse files
committed
feat: (wip) tests for dep resolver stub
1 parent c28bd3d commit 9c7f697

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

.labrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
exports.globals = [
4+
'Symbol(__RESOLVED_TEMP_DIRECTORY__)'
5+
].join(',');

lib/deps.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,18 @@ internals.walk = (node, callback) => {
1313

1414
callback(node);
1515

16-
if (!node.children) {
17-
return;
18-
}
19-
2016
node.children.forEach((child) => {
2117

2218
internals.walk(child, callback);
2319
});
2420
};
2521

2622

27-
exports.resolve = async (packageJson) => {
28-
29-
// @todo: handle lock files
23+
exports.resolve = async ({ packageJson, lockfile }) => {
3024

3125
const path = Tempy.directory();
3226
Fs.writeFileSync(Path.join(path, 'package.json'), JSON.stringify(packageJson, null, ' '));
27+
Fs.writeFileSync(Path.join(path, 'package-lock.json'), JSON.stringify(lockfile, null, ' '));
3328

3429
const arborist = new Arborist({ path });
3530

test/deps.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const Fs = require('fs');
4+
const Path = require('path');
5+
6+
const Deps = require('../lib/deps');
7+
8+
9+
const { describe, it } = exports.lab = require('@hapi/lab').script();
10+
const { expect } = require('@hapi/code');
11+
12+
describe('Deps', () => {
13+
14+
describe('resolve', () => {
15+
16+
it('returns flattened list of deps', async () => {
17+
18+
const result = await Deps.resolve({
19+
packageJson: JSON.parse(Fs.readFileSync(Path.join(__dirname, 'fixtures', 'deps-test-package.json'))),
20+
lockfile: JSON.parse(Fs.readFileSync(Path.join(__dirname, 'fixtures', 'deps-test-lock.json')))
21+
});
22+
23+
expect(result).to.equal({
24+
'ci-info': ['1.6.0', '2.0.0'],
25+
'is-ci': ['2.0.0']
26+
});
27+
});
28+
});
29+
});

test/fixtures/deps-test-lock.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"requires": true,
3+
"lockfileVersion": 1,
4+
"dependencies": {
5+
"ci-info": {
6+
"version": "1.6.0",
7+
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.6.0.tgz",
8+
"integrity": "sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A=="
9+
},
10+
"is-ci": {
11+
"version": "2.0.0",
12+
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz",
13+
"integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==",
14+
"requires": {
15+
"ci-info": "^2.0.0"
16+
},
17+
"dependencies": {
18+
"ci-info": {
19+
"version": "2.0.0",
20+
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz",
21+
"integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ=="
22+
}
23+
}
24+
}
25+
}
26+
}

test/fixtures/deps-test-package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"is-ci": "^2.0.0",
5+
"ci-info": "^1.6.0"
6+
}
7+
}

0 commit comments

Comments
 (0)