Skip to content

Commit 193fdbb

Browse files
authored
Improves 'yarn workspaces focus' tests (#6932)
## What's the problem this PR addresses? Our tests were relying on the presence of `.gitignore`, which isn't relevant for the feature being tested. ## How did you fix it? Removed the dependency on `.gitignore`. Also added some extra checks to make sure that not only are the packages correctly installed, but they can also be properly required at runtime. ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent 8ff18d7 commit 193fdbb

File tree

1 file changed

+65
-21
lines changed
  • packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces

1 file changed

+65
-21
lines changed

packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/focus.test.js

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import {ppath, xfs} from '@yarnpkg/fslib';
22

3+
async function getCacheContent(cacheFolder) {
4+
const cacheContent = (await xfs.readdirPromise(cacheFolder))
5+
.filter(file => !file.startsWith(`.`));
6+
7+
cacheContent.sort();
8+
9+
return cacheContent;
10+
}
11+
312
describe(`Commands`, () => {
413
describe(`workspaces focus`, () => {
514
test(
@@ -9,8 +18,8 @@ describe(`Commands`, () => {
918
private: true,
1019
workspaces: [`packages/*`],
1120
},
12-
async ({path, run}) => {
13-
await setupProject(path);
21+
async ({path, run, source}) => {
22+
await setupProject(path, source);
1423

1524
await run(`install`);
1625

@@ -21,10 +30,16 @@ describe(`Commands`, () => {
2130
cwd: ppath.join(path, `packages/foo`),
2231
});
2332

24-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
25-
`.gitignore`,
33+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
2634
expect.stringContaining(`no-deps-npm-1.0.0-`),
2735
]);
36+
37+
await expect(source(`require('no-deps')`, {
38+
cwd: ppath.join(path, `packages/foo`),
39+
})).resolves.toMatchObject({
40+
name: `no-deps`,
41+
version: `1.0.0`,
42+
});
2843
},
2944
),
3045
);
@@ -36,7 +51,7 @@ describe(`Commands`, () => {
3651
private: true,
3752
workspaces: [`packages/*`],
3853
},
39-
async ({path, run}) => {
54+
async ({path, run, source}) => {
4055
await setupProject(path);
4156

4257
await run(`install`);
@@ -48,11 +63,24 @@ describe(`Commands`, () => {
4863
cwd: ppath.join(path, `packages/foo`),
4964
});
5065

51-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
52-
`.gitignore`,
66+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
5367
expect.stringContaining(`no-deps-npm-1.0.0-`),
5468
expect.stringContaining(`no-deps-npm-2.0.0-`),
5569
]);
70+
71+
await expect(source(`require('no-deps')`, {
72+
cwd: ppath.join(path, `packages/foo`),
73+
})).resolves.toMatchObject({
74+
name: `no-deps`,
75+
version: `1.0.0`,
76+
});
77+
78+
await expect(source(`require('no-deps')`, {
79+
cwd: ppath.join(path, `packages/bar`),
80+
})).resolves.toMatchObject({
81+
name: `no-deps`,
82+
version: `2.0.0`,
83+
});
5684
},
5785
),
5886
);
@@ -64,7 +92,7 @@ describe(`Commands`, () => {
6492
private: true,
6593
workspaces: [`packages/*`],
6694
},
67-
async ({path, run}) => {
95+
async ({path, run, source}) => {
6896
await setupProject(path);
6997

7098
await run(`install`);
@@ -76,10 +104,16 @@ describe(`Commands`, () => {
76104
cwd: ppath.join(path, `packages/baz`),
77105
});
78106

79-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
80-
`.gitignore`,
107+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
81108
expect.stringContaining(`no-deps-npm-2.0.0-`),
82109
]);
110+
111+
await expect(source(`require('no-deps')`, {
112+
cwd: ppath.join(path, `packages/bar`),
113+
})).resolves.toMatchObject({
114+
name: `no-deps`,
115+
version: `2.0.0`,
116+
});
83117
},
84118
),
85119
);
@@ -91,19 +125,25 @@ describe(`Commands`, () => {
91125
private: true,
92126
workspaces: [`packages/*`],
93127
},
94-
async ({path, run}) => {
128+
async ({path, run, source}) => {
95129
await setupProject(path);
96130

97131
await run(`workspaces`, `focus`, {
98132
cwd: ppath.join(path, `packages/quux`),
99133
});
100134

101135
const cacheFolder = ppath.join(path, `.yarn/cache`);
102-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
103-
`.gitignore`,
136+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
104137
expect.stringContaining(`no-deps-npm-1.0.0-`),
105138
expect.stringContaining(`no-deps-npm-2.0.0-`),
106139
]);
140+
141+
await expect(source(`require('no-deps')`, {
142+
cwd: ppath.join(path, `packages/quux`),
143+
})).resolves.toMatchObject({
144+
name: `no-deps`,
145+
version: `1.0.0`,
146+
});
107147
},
108148
),
109149
);
@@ -115,16 +155,15 @@ describe(`Commands`, () => {
115155
private: true,
116156
workspaces: [`packages/*`],
117157
},
118-
async ({path, run}) => {
158+
async ({path, run, source}) => {
119159
await setupProject(path);
120160

121161
await run(`workspaces`, `focus`, `quux`, `--production`, {
122162
cwd: path,
123163
});
124164

125165
const cacheFolder = ppath.join(path, `.yarn/cache`);
126-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
127-
`.gitignore`,
166+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
128167
expect.stringContaining(`no-deps-npm-1.0.0-`),
129168
]);
130169
},
@@ -138,7 +177,7 @@ describe(`Commands`, () => {
138177
private: true,
139178
workspaces: [`packages/*`],
140179
},
141-
async ({path, run}) => {
180+
async ({path, run, source}) => {
142181
await setupProject(path);
143182

144183
await run(`install`);
@@ -150,11 +189,17 @@ describe(`Commands`, () => {
150189
cwd: path,
151190
});
152191

153-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
154-
`.gitignore`,
192+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
155193
expect.stringContaining(`no-deps-bins-npm-1.0.0-`),
156194
expect.stringContaining(`no-deps-npm-1.0.0-`),
157195
]);
196+
197+
await expect(source(`require('no-deps-bins')`, {
198+
cwd: ppath.join(path, `packages/qux`),
199+
})).resolves.toMatchObject({
200+
name: `no-deps-bins`,
201+
version: `1.0.0`,
202+
});
158203
},
159204
),
160205
);
@@ -178,8 +223,7 @@ describe(`Commands`, () => {
178223
cwd: path,
179224
});
180225

181-
await expect(xfs.readdirPromise(cacheFolder)).resolves.toEqual([
182-
`.gitignore`,
226+
await expect(getCacheContent(cacheFolder)).resolves.toEqual([
183227
expect.stringContaining(`no-deps-npm-1.0.0-`),
184228
]);
185229
},

0 commit comments

Comments
 (0)