-
Notifications
You must be signed in to change notification settings - Fork 10
/
index-tests.js
99 lines (86 loc) · 3.49 KB
/
index-tests.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
var resolvePackagePath = require('../');
var Project = require('fixturify-project');
var fs = require('fs-extra');
var FIXTURE_ROOT = `${__dirname}/tmp/fixtures/`
var expect = require('chai').expect;
var path = require('path');
var semver = require('semver');
var Project = require('fixturify-project');
describe('resolve-package-path', function() {
beforeEach(function() {
fs.removeSync(FIXTURE_ROOT);
});
afterEach(function() {
fs.removeSync(FIXTURE_ROOT);
});
it('exposes its cache', function() {
expect(resolvePackagePath._CACHE).to.be.ok;
expect(resolvePackagePath._resetCache).to.be.a('function');
});
it('appears to reset cache', function() {
resolvePackagePath._CACHE.PATH.set('hi', 1);
expect(resolvePackagePath._CACHE.PATH.has('hi')).eql(true);
resolvePackagePath._resetCache();
expect(resolvePackagePath._CACHE.PATH.has('hi')).eql(false);
});
describe('npm usage', function() {
it('smoke test', function() {
var rsvp, a, orange, apple;
var app = new Project('app', '3.1.1', app => {
rsvp = app.addDependency('rsvp', '3.2.2', rsvp => {
a = rsvp.addDependency('a', '1.1.1');
});
orange = app.addDependency('orange', '1.0.0');
apple = app.addDependency('apple', '1.0.0');
});
app.writeSync();
expect(resolvePackagePath('app', app.root)). to.eql(null);
expect(resolvePackagePath('rsvp', app.baseDir)). to.eql(path.normalize(`${app.root}/app/node_modules/rsvp/package.json`));
expect(resolvePackagePath('orange', app.baseDir)). to.eql(path.normalize(`${app.root}/app/node_modules/orange/package.json`));
expect(resolvePackagePath('apple', app.baseDir)). to.eql(path.normalize(`${app.root}/app/node_modules/apple/package.json`));
expect(resolvePackagePath('a', app.baseDir)). to.eql(null);
expect(resolvePackagePath('a', rsvp.baseDir)).to.eql(path.normalize(`${rsvp.baseDir}/node_modules/a/package.json`));
expect(resolvePackagePath('rsvp', a.baseDir)). to.eql(path.normalize(`${rsvp.baseDir}/package.json`));
expect(resolvePackagePath('orange', a.baseDir)). to.eql(path.normalize(`${orange.baseDir}/package.json`));
expect(resolvePackagePath('apple', a.baseDir)). to.eql(path.normalize(`${apple.baseDir}/package.json`));
expect(resolvePackagePath('app', a.baseDir)). to.eql(null);
});
});
if (semver.gte(process.versions.node, '8.0.0')) {
describe('yarn pnp usage', function() {
this.timeout(30000); // in-case the network IO is slow
var app;
var execa = require('execa');
beforeEach(function() {
app = new Project('dummy', '1.0.0', app => {
app.pkg.private = true;
app.pkg.name
app.pkg.scripts = {
test: "node -r ./.pnp.js ./test.js"
};
app.pkg.installConfig = {
pnp: true
};
app.addDependency('ember-source-channel-url', '1.1.0');
app.addDependency('resolve-package-path', 'link:' + path.join(__dirname, '..'));
app.files = {
'test.js': 'require("resolve-package-path")("ember-source-channel-url", __dirname)'
};
});
app.writeSync();
execa.sync('yarn', {
cwd: app.baseDir
})
});
afterEach(function() {
app.dispose();
});
it('handles yarn pnp usage', function() {
execa.sync('yarn', ['test'], {
cwd: app.baseDir
});
});
});
}
});