Skip to content

Commit b345544

Browse files
committed
Replace jest-fixtures with fixturez
1 parent 8978178 commit b345544

34 files changed

Lines changed: 363 additions & 459 deletions

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
"babel-plugin-transform-runtime": "^6.23.0",
3232
"babel-preset-env": "^1.6.0",
3333
"babel-preset-flow": "^6.23.0",
34+
"fixturez": "^1.1.0",
3435
"flow-bin": "^0.63.1",
3536
"husky": "^0.14.3",
3637
"jest": "^20.0.4",
3738
"jest-expect-contain-deep": "^1.0.1",
38-
"jest-fixtures": "^0.5.0",
3939
"lint-staged": "^4.1.3",
4040
"mode-to-permissions": "^0.0.2",
4141
"path-exists": "^3.0.0",

‎src/__tests__/Config.test.js‎

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@ import Config from '../Config';
33
import * as fs from '../utils/fs';
44
import { mkdtempSync } from 'fs';
55
import * as path from 'path';
6-
import { getFixturePath } from 'jest-fixtures';
6+
import fixtures from 'fixturez';
7+
8+
const f = fixtures(__dirname);
79

810
jest.mock('../utils/logger');
911

1012
describe('Config.init', () => {
1113
it('should read a valid package.json file', async () => {
12-
let filePath = await getFixturePath(
13-
__dirname,
14-
'simple-package',
15-
'package.json'
16-
);
14+
let filePath = path.join(f.find('simple-package'), 'package.json');
1715
let pkg = await Config.init(filePath);
18-
expect(pkg.json).toMatchObject({
19-
name: 'fixture-basic'
20-
});
16+
expect(pkg.json).toMatchObject({ name: 'fixture-basic' });
2117
});
2218

2319
it('should error on an invalid package.json file', async () => {
24-
let filePath = await getFixturePath(
25-
__dirname,
26-
'package-with-invalid-json',
20+
let filePath = path.join(
21+
f.find('package-with-invalid-json'),
2722
'package.json'
2823
);
2924
return expect(Config.init(filePath)).rejects.toBeDefined();
@@ -42,11 +37,7 @@ describe('writeConfigFile', () => {
4237
});
4338

4439
it('should write a json file', async () => {
45-
let filePath = await getFixturePath(
46-
__dirname,
47-
'simple-package',
48-
'package.json'
49-
);
40+
let filePath = path.join(f.find('simple-package'), 'package.json');
5041
let json = { name: 'wat', version: '0.0.0' };
5142
let fileContents = JSON.stringify(json, null, 2);
5243
let config = await Config.init(filePath);
@@ -55,9 +46,8 @@ describe('writeConfigFile', () => {
5546
});
5647

5748
it('should write a json file with correct-indentation', async () => {
58-
let filePath = await getFixturePath(
59-
__dirname,
60-
'package-with-four-spaces-json',
49+
let filePath = path.join(
50+
f.find('package-with-four-spaces-json'),
6151
'package.json'
6252
);
6353
let json = { name: 'wat', version: '0.0.0' };
@@ -68,9 +58,8 @@ describe('writeConfigFile', () => {
6858
});
6959

7060
it('should write a json file with correct-indentation when uncertain', async () => {
71-
let filePath = await getFixturePath(
72-
__dirname,
73-
'package-with-uncertain-indentation-json',
61+
let filePath = path.join(
62+
f.find('package-with-uncertain-indentation-json'),
7463
'package.json'
7564
);
7665
let json = { name: 'wat', version: '0.0.0' };
@@ -83,28 +72,19 @@ describe('writeConfigFile', () => {
8372

8473
describe('getProjectConfig()', () => {
8574
it('should get the root if it is the current directory', async () => {
86-
let fixturePath = await getFixturePath(__dirname, 'simple-project');
75+
let fixturePath = f.find('simple-package');
8776
let found = await Config.getProjectConfig(fixturePath);
8877
expect(found).toBe(path.join(fixturePath, 'package.json'));
8978
});
9079

9180
it('should get the root if in nested non-package directory', async () => {
92-
let fixturePath = await getFixturePath(
93-
__dirname,
94-
'simple-project',
95-
'packages'
96-
);
81+
let fixturePath = path.join(f.find('simple-package'), 'packages');
9782
let found = await Config.getProjectConfig(fixturePath);
9883
expect(found).toBe(path.join(fixturePath, '..', 'package.json'));
9984
});
10085

10186
it('should get the root if in nested package directory', async () => {
102-
let fixturePath = await getFixturePath(
103-
__dirname,
104-
'simple-project',
105-
'packages',
106-
'bar'
107-
);
87+
let fixturePath = path.join(f.find('simple-package'), 'packages', 'bar');
10888
let found = await Config.getProjectConfig(fixturePath);
10989
expect(found).toBe(path.join(fixturePath, '..', '..', 'package.json'));
11090
});
@@ -116,9 +96,8 @@ describe('getProjectConfig()', () => {
11696
});
11797

11898
it('should get the root if in nested package not included in a parent project', async () => {
119-
let fixturePath = await getFixturePath(
120-
__dirname,
121-
'simple-project-with-excluded-package',
99+
let fixturePath = path.join(
100+
f.find('simple-project-with-excluded-package'),
122101
'packages',
123102
'bar'
124103
);

‎src/__tests__/Package.test.js‎

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ import Config from '../Config';
44
import * as fs from '../utils/fs';
55
import { mkdtempSync } from 'fs';
66
import * as path from 'path';
7-
import { getFixturePath } from 'jest-fixtures';
7+
import fixtures from 'fixturez';
8+
9+
const f = fixtures(__dirname);
810

911
jest.mock('../utils/logger');
1012

1113
describe('Package', () => {
1214
describe('init()', () => {
1315
it('should return a valid Package', async () => {
14-
let filePath = await getFixturePath(
15-
__dirname,
16-
'simple-package',
17-
'package.json'
18-
);
16+
let filePath = path.join(f.find('simple-package'), 'package.json');
1917
let pkg = await Package.init(filePath);
2018

2119
expect(pkg).toBeInstanceOf(Package);
@@ -24,9 +22,8 @@ describe('Package', () => {
2422
});
2523

2624
it('should error on an invalid package.json file', async () => {
27-
let filePath = await getFixturePath(
28-
__dirname,
29-
'package-with-invalid-json',
25+
let filePath = path.join(
26+
f.find('package-with-invalid-json'),
3027
'package.json'
3128
);
3229
return expect(Package.init(filePath)).rejects.toBeDefined();
@@ -35,20 +32,15 @@ describe('Package', () => {
3532

3633
describe('getDependencyTypes', () => {
3734
it('should return dependency type of a dependency', async () => {
38-
let filePath = await getFixturePath(
39-
__dirname,
40-
'nested-workspaces',
41-
'package.json'
42-
);
35+
let filePath = path.join(f.find('nested-workspaces'), 'package.json');
4336
let pkg = await Package.init(filePath);
4437
const depTypes = pkg.getDependencyTypes('react');
4538
expect(depTypes).toEqual(['dependencies']);
4639
});
4740

4841
it('should return multiple dependency types if they exist', async () => {
49-
let filePath = await getFixturePath(
50-
__dirname,
51-
'simple-project-with-multiple-depTypes',
42+
let filePath = path.join(
43+
f.find('simple-project-with-multiple-depTypes'),
5244
'package.json'
5345
);
5446
let pkg = await Package.init(filePath);
@@ -57,11 +49,7 @@ describe('Package', () => {
5749
});
5850

5951
it('should return an empty array if dep does not exist', async () => {
60-
let filePath = await getFixturePath(
61-
__dirname,
62-
'simple-package',
63-
'package.json'
64-
);
52+
let filePath = path.join(f.find('simple-package'), 'package.json');
6553
let pkg = await Package.init(filePath);
6654
let depTypes = pkg.getDependencyTypes('non-existent-dep');
6755
expect(depTypes).toEqual([]);

‎src/__tests__/Project.test.js‎

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Project from '../Project';
44
import Package from '../Package';
55
import Workspace from '../Workspace';
66
import * as logger from '../utils/logger';
7+
import fixtures from 'fixturez';
78

8-
import { getFixturePath } from 'jest-fixtures';
9+
const f = fixtures(__dirname);
910

1011
jest.mock('../utils/logger');
1112

@@ -34,7 +35,7 @@ describe('Project', () => {
3435

3536
describe('A simple project', () => {
3637
beforeEach(async () => {
37-
const filePath = await getFixturePath(__dirname, 'simple-project');
38+
let filePath = f.find('simple-project');
3839
project = await Project.init(filePath);
3940
});
4041

@@ -44,14 +45,14 @@ describe('Project', () => {
4445
});
4546

4647
it('should be able to getWorkspaces', async () => {
47-
const workspaces = await project.getWorkspaces();
48+
let workspaces = await project.getWorkspaces();
4849
expect(workspaces.length).toEqual(2);
4950
expect(workspaces[0]).toBeInstanceOf(Workspace);
5051
});
5152

5253
it('should be able to runWorkspaceTasks', async () => {
53-
const workspaces = await project.getWorkspaces();
54-
const spy = jest.fn(() => Promise.resolve());
54+
let workspaces = await project.getWorkspaces();
55+
let spy = jest.fn(() => Promise.resolve());
5556

5657
await project.runWorkspaceTasks(workspaces, spy);
5758

@@ -63,20 +64,20 @@ describe('Project', () => {
6364

6465
describe('A project with nested workspaces', () => {
6566
beforeEach(async () => {
66-
const filePath = await getFixturePath(__dirname, 'nested-workspaces');
67+
let filePath = f.find('nested-workspaces');
6768
project = await Project.init(filePath);
6869
});
6970

7071
it('should be able to getWorkspaces (including nested)', async () => {
71-
const workspaces = await project.getWorkspaces();
72+
let workspaces = await project.getWorkspaces();
7273
expect(workspaces.length).toEqual(3);
7374
expect(workspaces[0]).toBeInstanceOf(Workspace);
7475
});
7576

7677
it('should be able to getDependencyGraph', async () => {
77-
const workspaces = await project.getWorkspaces();
78-
const { valid, graph } = await project.getDependencyGraph(workspaces);
79-
const expectedDependencies = {
78+
let workspaces = await project.getWorkspaces();
79+
let { valid, graph } = await project.getDependencyGraph(workspaces);
80+
let expectedDependencies = {
8081
'fixture-project-nested-workspaces': [],
8182
foo: ['bar'],
8283
bar: [],
@@ -93,9 +94,9 @@ describe('Project', () => {
9394
});
9495

9596
it('should be able to getDependentsGraph', async () => {
96-
const workspaces = await project.getWorkspaces();
97-
const { valid, graph } = await project.getDependentsGraph(workspaces);
98-
const expectedDependents = {
97+
let workspaces = await project.getWorkspaces();
98+
let { valid, graph } = await project.getDependentsGraph(workspaces);
99+
let expectedDependents = {
99100
bar: ['foo', 'baz'],
100101
foo: [],
101102
baz: []
@@ -113,23 +114,20 @@ describe('Project', () => {
113114

114115
describe('A project with nested workspaces and transitive dependents', () => {
115116
beforeEach(async () => {
116-
const filePath = await getFixturePath(
117-
__dirname,
118-
'nested-workspaces-transitive-dependents'
119-
);
117+
let filePath = f.find('nested-workspaces-transitive-dependents');
120118
project = await Project.init(filePath);
121119
});
122120

123121
it('should be able to getWorkspaces (including nested)', async () => {
124-
const workspaces = await project.getWorkspaces();
122+
let workspaces = await project.getWorkspaces();
125123
expect(workspaces.length).toEqual(4);
126124
expect(workspaces[0]).toBeInstanceOf(Workspace);
127125
});
128126

129127
it('should be able to getDependencyGraph', async () => {
130-
const workspaces = await project.getWorkspaces();
131-
const { valid, graph } = await project.getDependencyGraph(workspaces);
132-
const expectedDependencies = {
128+
let workspaces = await project.getWorkspaces();
129+
let { valid, graph } = await project.getDependencyGraph(workspaces);
130+
let expectedDependencies = {
133131
'nested-workspaces-transitive-dependents': [],
134132
'pkg-a': [],
135133
'workspace-a': ['pkg-a'],
@@ -141,8 +139,8 @@ describe('Project', () => {
141139
expect(graph).toBeInstanceOf(Map);
142140
expect(graph.size).toBe(Object.keys(expectedDependencies).length);
143141

144-
const assertDependencies = (pkg, deps) => {
145-
const val = graph.get(pkg);
142+
let assertDependencies = (pkg, deps) => {
143+
let val = graph.get(pkg);
146144
expect(val && val.dependencies).toEqual(deps);
147145
};
148146

@@ -152,9 +150,9 @@ describe('Project', () => {
152150
});
153151

154152
it('should be able to getDependentsGraph', async () => {
155-
const workspaces = await project.getWorkspaces();
156-
const { valid, graph } = await project.getDependentsGraph(workspaces);
157-
const expectedDependents = {
153+
let workspaces = await project.getWorkspaces();
154+
let { valid, graph } = await project.getDependentsGraph(workspaces);
155+
let expectedDependents = {
158156
'pkg-a': ['workspace-a', 'pkg-b'],
159157
'workspace-a': [],
160158
'pkg-b': ['pkg-c'],
@@ -177,7 +175,7 @@ describe('Project', () => {
177175
let workspaces;
178176

179177
beforeEach(async () => {
180-
cwd = await getFixturePath(__dirname, 'nested-workspaces');
178+
cwd = f.find('nested-workspaces');
181179
project = project = await Project.init(cwd);
182180
workspaces = await project.getWorkspaces();
183181
});
@@ -245,10 +243,7 @@ describe('Project', () => {
245243
});
246244

247245
it('should support scoped workspaces', async () => {
248-
cwd = await getFixturePath(
249-
__dirname,
250-
'nested-workspaces-with-scoped-package-names'
251-
);
246+
cwd = f.find('nested-workspaces-with-scoped-package-names');
252247
project = project = await Project.init(cwd);
253248
workspaces = await project.getWorkspaces();
254249

@@ -272,7 +267,7 @@ describe('Project', () => {
272267

273268
describe('runWorkspaceTasks()', () => {
274269
test('independent workspaces', async () => {
275-
let cwd = await getFixturePath(__dirname, 'independent-workspaces');
270+
let cwd = f.find('independent-workspaces');
276271
let project = await Project.init(cwd);
277272
let workspaces = await project.getWorkspaces();
278273
let ops = [];
@@ -288,7 +283,7 @@ describe('Project', () => {
288283
});
289284

290285
test('dependent workspaces', async () => {
291-
let cwd = await getFixturePath(__dirname, 'dependent-workspaces');
286+
let cwd = f.find('dependent-workspaces');
292287
let project = await Project.init(cwd);
293288
let workspaces = await project.getWorkspaces();
294289
let ops = [];
@@ -304,10 +299,7 @@ describe('Project', () => {
304299
});
305300

306301
test('dependent workspaces with cycle', async () => {
307-
let cwd = await getFixturePath(
308-
__dirname,
309-
'dependent-workspaces-with-cycle'
310-
);
302+
let cwd = f.find('dependent-workspaces-with-cycle');
311303
let project = await Project.init(cwd);
312304
let workspaces = await project.getWorkspaces();
313305
let ops = [];

0 commit comments

Comments
 (0)