-
Notifications
You must be signed in to change notification settings - Fork 956
Expand file tree
/
Copy pathdev-dependencies.e2e.ts
More file actions
205 lines (196 loc) · 8.93 KB
/
Copy pathdev-dependencies.e2e.ts
File metadata and controls
205 lines (196 loc) · 8.93 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import chai, { expect } from 'chai';
import { Extensions } from '@teambit/legacy.constants';
import { Helper } from '@teambit/legacy.e2e-helper';
import chaiFs from 'chai-fs';
chai.use(chaiFs);
describe('dev-dependencies functionality', function () {
this.timeout(0);
let helper: Helper;
before(() => {
helper = new Helper();
});
after(() => {
helper.scopeHelper.destroy();
});
describe('environment with compiler and tester', () => {
describe('with dev-dependencies same as dependencies', () => {
let comp1;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
helper.fixtures.populateComponents();
helper.fs.outputFile('comp1/foo.spec.js', 'require("chai");');
helper.npm.addFakeNpmPackage('chai', '4.1.2');
helper.workspaceJsonc.addPolicyToDependencyResolver({ dependencies: 'chai@4.1.2' });
helper.command.tagAllWithoutBuild();
comp1 = helper.command.catComponent('comp1@0.0.1');
});
it('should not save the dev-dependencies because they are the same as dependencies', () => {
expect(comp1.devDependencies).to.be.an('array').that.is.empty;
});
it('should save "chai" in the dev-packages because it is only required in the tests files', () => {
expect(comp1.devPackageDependencies).to.be.an('object').that.has.property('chai');
});
it('should not save "chai" in the packages because it is not required in non-test files', () => {
expect(comp1.packageDependencies).to.be.an('object').that.is.empty;
});
it('should leave the dependencies intact', () => {
expect(comp1.dependencies).to.be.an('array').that.have.lengthOf(1);
expect(comp1.dependencies[0].id.name).to.equal('comp2');
expect(comp1.dependencies[0].id.version).to.equal('0.0.1');
});
it('should leave the flattened-dependencies intact', () => {
expect(comp1.flattenedDependencies).to.deep.include({
name: 'comp3',
scope: helper.scopes.remote,
version: '0.0.1',
});
expect(comp1.flattenedDependencies).to.deep.include({
name: 'comp2',
scope: helper.scopes.remote,
version: '0.0.1',
});
});
});
describe('without dependencies and with dev-dependencies', () => {
let comp1;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
// foo.js doesn't have any dependencies. foo.spec.js does have dependencies.
helper.fixtures.populateComponents();
helper.fs.outputFile('comp1/foo.spec.js', `require("chai"); require('@${helper.scopes.remote}/comp2');`);
helper.fs.outputFile('comp1/index.js', '');
helper.npm.addFakeNpmPackage('chai', '4.1.2');
helper.workspaceJsonc.addPolicyToDependencyResolver({ dependencies: 'chai@4.1.2' });
helper.command.tagAllWithoutBuild();
comp1 = helper.command.catComponent('comp1@0.0.1');
});
it('should save the dev-dependencies', () => {
expect(comp1.devDependencies).to.be.an('array').that.have.lengthOf(1);
expect(comp1.devDependencies[0].id).to.deep.equal({
name: 'comp2',
scope: helper.scopes.remote,
version: '0.0.1',
});
});
it('should save the flattened-dependencies', () => {
expect(comp1.flattenedDependencies).to.deep.include({
name: 'comp3',
scope: helper.scopes.remote,
version: '0.0.1',
});
expect(comp1.flattenedDependencies).to.deep.include({
name: 'comp2',
scope: helper.scopes.remote,
version: '0.0.1',
});
});
it('should save "chai" in the dev-packages', () => {
expect(comp1.devPackageDependencies).to.be.an('object').that.has.property('chai');
});
it('should not save "chai" in the packages', () => {
expect(comp1.packageDependencies).to.be.an('object').that.is.empty;
});
it('should not save anything into dependencies', () => {
expect(comp1.dependencies).to.be.an('array').that.is.empty;
});
it('should save the flattened dev-dependencies into flattened-dependencies', () => {
expect(comp1.flattenedDependencies).to.be.an('array').with.lengthOf(2);
});
it('bit status should not show any component as modified', () => {
const output = helper.command.runCmd('bit status');
expect(output).to.have.string('staged components');
});
});
});
// (bar ->(prod)-> is-string ->(dev)->is-type ->(prod)-> baz)
describe('dev-dependency of a nested component that originated from a prod dep', () => {
let output;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
helper.fixtures.populateComponents(4);
helper.fs.moveSync('comp2/index.js', 'comp2/foo.spec.js');
helper.fs.outputFile('comp2/index.js');
helper.command.tagAllWithoutBuild();
helper.command.export();
helper.scopeHelper.reInitWorkspace();
helper.scopeHelper.addRemoteScope();
output = helper.command.importComponent('*');
});
it('should be able to import with no errors', () => {
expect(output).to.have.string('successfully imported');
});
it('bit status should show a clean state', () => {
helper.command.expectStatusToBeClean();
});
it('the nested dev-dependency and nested prod of the nested dev-dependency should be saved in the flattenedDependencies', () => {
const barFoo = helper.command.catComponent(`${helper.scopes.remote}/comp1@latest`);
expect(barFoo.flattenedDependencies).to.have.lengthOf(3);
const names = barFoo.flattenedDependencies.map((d) => d.name);
expect(names).to.deep.equal(['comp2', 'comp3', 'comp4']);
});
});
// (comp1 ->(dev)-> comp2 ->(dev)->comp3
describe('dev-dependency of a nested component that originated from a dev dep', () => {
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
helper.fixtures.populateComponents(3);
helper.fs.moveSync('comp1/index.js', 'comp1/foo.spec.js');
helper.fs.outputFile('comp1/index.js');
helper.fs.moveSync('comp2/index.js', 'comp2/foo.spec.js');
helper.fs.outputFile('comp2/index.js');
helper.fs.outputFile('comp3/index.js');
helper.command.tagAllWithoutBuild();
});
it('the flattened dependencies should contain the entire chain of the dependencies', () => {
const barFoo = helper.command.catComponent('comp1@latest');
const names = barFoo.flattenedDependencies.map((d) => d.name);
expect(names).to.include('comp3');
expect(names).to.include('comp2');
});
});
describe('dev-dependency that requires prod-dependency', () => {
let barFoo;
before(() => {
helper.scopeHelper.reInitWorkspace();
helper.fixtures.populateComponents(3);
helper.fs.moveSync('comp1/index.js', 'comp1/foo.spec.js');
helper.fs.outputFile('comp1/index.js');
helper.command.tagAllWithoutBuild();
barFoo = helper.command.catComponent('comp1@latest');
// as an intermediate step, make sure barFoo has is-string as a dev dependency only
expect(barFoo.dependencies).to.have.lengthOf(0);
expect(barFoo.devDependencies).to.have.lengthOf(1);
expect(barFoo.devDependencies[0].id.name).to.equal('comp2');
});
it('should include the prod dependencies inside flattenedDependencies', () => {
expect(barFoo.flattenedDependencies).to.deep.include({
name: 'comp3',
scope: helper.scopes.remote,
version: '0.0.1',
});
});
});
describe('component with devDependency coming from an env and is used as prod', () => {
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
const envName = helper.env.setCustomEnv('node-env-dev-dep');
const envId = `${helper.scopes.remote}/${envName}`;
helper.extensions.addExtensionToVariant('*', envId);
helper.fixtures.populateComponents(1, false);
helper.fs.outputFile(`comp1/index.js`, `const isPositive = require('is-positive');`);
// the custom env composes @teambit/node, whose aspect chain also requires the react and
// aspect env packages from the workspace root (they used to be core aspects). install them
// so the env loads, then run another install so its dependency policies (is-positive as a
// dev dep) are applied to the components.
helper.command.install('@teambit/react@1.0.1042 @teambit/aspect@1.0.1042');
helper.command.install();
helper.command.tagWithoutBuild();
});
it('should be able to remove it from DevDependency only by "bit deps remove --dev"', () => {
helper.command.dependenciesRemove('comp1', 'is-positive', '--dev');
const bitMap = helper.bitMap.read();
expect(bitMap.comp1.config[Extensions.dependencyResolver].policy).to.have.property('devDependencies');
expect(bitMap.comp1.config[Extensions.dependencyResolver].policy.devDependencies['is-positive']).to.equal('-');
});
});
});