This repository was archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathlink.test.js
More file actions
84 lines (65 loc) · 3.51 KB
/
Copy pathlink.test.js
File metadata and controls
84 lines (65 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict'
require('../setup')
import linkLibs from '../../src/scripts/link.js';
import ZosPackageFile from "../../src/models/files/ZosPackageFile";
const should = require('chai').should();
contract('link script', function() {
const shouldHaveDependency = function(name, version) {
should.exist(this.packageFile.getDependencyVersion(name))
this.packageFile.getDependencyVersion(name).should.eq(version)
}
beforeEach('setup', async function() {
this.packageFile = new ZosPackageFile('test/mocks/packages/package-with-stdlib.zos.json')
this.shouldHaveDependency = shouldHaveDependency.bind(this)
});
it('should set a dependency', async function () {
await linkLibs({ libs: ['mock-stdlib@1.1.0'], packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '1.1.0');
});
it('should set multiple dependencies', async function () {
const libs = ['mock-stdlib@1.1.0', 'mock-stdlib-2@1.2.0'];
await linkLibs({ libs, packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '1.1.0');
this.shouldHaveDependency('mock-stdlib-2', '1.2.0');
});
it('should overwrite a dependency version', async function () {
const initialLibs = ['mock-stdlib@^1.0.0', 'mock-stdlib-2@1.2.0']
const withUpdatedLib = ['mock-stdlib@~1.1.0']
await linkLibs({ libs: initialLibs, packageFile: this.packageFile });
await linkLibs({ libs: withUpdatedLib, packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '~1.1.0');
this.shouldHaveDependency('mock-stdlib-2', '1.2.0');
});
it('should install all dependencies if requested', async function () {
const libs = ['mock-stdlib@1.1.0', 'mock-stdlib-2@1.2.0']
await linkLibs({ libs, installLib: true, packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '1.1.0');
this.shouldHaveDependency('mock-stdlib-2', '1.2.0');
});
it('should refuse to set a dependency for a lib project', async function () {
this.packageFile.lib = true
await linkLibs({ libs: ['mock-stdlib@1.1.0'], packageFile: this.packageFile })
.should.be.rejectedWith('Package projects cannot use other packages.');
});
it('should allow mismatching npm and zos versions', async function () {
// mock-stdlib-invalid has npm version 1.1.0 but zos version 2.0.0
await linkLibs({ libs: ['mock-stdlib-invalid@1.1.0'], packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '1.1.0');
});
it('should install the dependency if a valid version range is requested', async function () {
await linkLibs({ libs: ['mock-stdlib@^1.0.0'], installLib: true, packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '^1.0.0');
});
it('should install the dependency if no version is requested', async function () {
await linkLibs({ libs: ['mock-stdlib'], installLib: true, packageFile: this.packageFile });
this.shouldHaveDependency('mock-stdlib', '^1.1.0');
});
it('should raise an error if requested version range does not match its package version', async function () {
await linkLibs({ libs: ['mock-stdlib@~1.0.0'], packageFile: this.packageFile })
.should.be.rejectedWith('mock-stdlib requires package version ~1.0.0, but 1.1.0 was found.')
});
it('should raise an error if requested version of dependency lacks zosversion identifier', async function () {
await linkLibs({ libs: ['mock-stdlib-unsupported@1.1.0'], packageFile: this.packageFile })
.should.be.rejectedWith(/zos version identifier not found/i)
});
})