Skip to content

Commit 30abbd6

Browse files
committed
Merge branch 'add-first-flow' into add-functional-tests
2 parents 2165fe8 + fec220a commit 30abbd6

7 files changed

Lines changed: 260 additions & 229 deletions

File tree

src/monorepo-workflow-operations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as editorModule from './editor';
88
import * as envModule from './env';
99
import * as packageModule from './package';
1010
import type { Package } from './package';
11-
import type { ValidatedManifest } from './package-manifest';
11+
import type { ValidatedPackageManifest } from './package-manifest';
1212
import type { Project } from './project';
1313
import * as releaseSpecificationModule from './release-specification';
1414
import * as workflowOperations from './workflow-operations';
@@ -1566,7 +1566,7 @@ function buildMockMonorepoRootPackage(
15661566
name = 'root',
15671567
version = '2022.1.1',
15681568
overrides: Omit<Partial<Package>, 'manifest'> & {
1569-
manifest?: Partial<ValidatedManifest>;
1569+
manifest?: Partial<ValidatedPackageManifest>;
15701570
} = {},
15711571
) {
15721572
const { manifest, ...rest } = overrides;

src/package-manifest.test.ts

Lines changed: 103 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import fs from 'fs';
22
import path from 'path';
33
import { SemVer } from 'semver';
44
import { withSandbox } from '../tests/helpers';
5-
import { readManifest } from './package-manifest';
5+
import { readPackageManifest } from './package-manifest';
66

77
describe('package-manifest', () => {
8-
describe('readManifest', () => {
8+
describe('readPackageManifest', () => {
99
it('reads a minimal package manifest, expanding it by filling in values for optional fields', async () => {
1010
await withSandbox(async (sandbox) => {
1111
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
@@ -17,7 +17,59 @@ describe('package-manifest', () => {
1717
}),
1818
);
1919

20-
expect(await readManifest(manifestPath)).toStrictEqual({
20+
expect(await readPackageManifest(manifestPath)).toStrictEqual({
21+
name: 'foo',
22+
version: new SemVer('1.2.3'),
23+
workspaces: [],
24+
private: false,
25+
bundledDependencies: {},
26+
dependencies: {},
27+
devDependencies: {},
28+
optionalDependencies: {},
29+
peerDependencies: {},
30+
});
31+
});
32+
});
33+
34+
it('reads a package manifest where "private" is true', async () => {
35+
await withSandbox(async (sandbox) => {
36+
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
37+
await fs.promises.writeFile(
38+
manifestPath,
39+
JSON.stringify({
40+
name: 'foo',
41+
version: '1.2.3',
42+
private: true,
43+
}),
44+
);
45+
46+
expect(await readPackageManifest(manifestPath)).toStrictEqual({
47+
name: 'foo',
48+
version: new SemVer('1.2.3'),
49+
workspaces: [],
50+
private: true,
51+
bundledDependencies: {},
52+
dependencies: {},
53+
devDependencies: {},
54+
optionalDependencies: {},
55+
peerDependencies: {},
56+
});
57+
});
58+
});
59+
60+
it('reads a package manifest where "private" is false', async () => {
61+
await withSandbox(async (sandbox) => {
62+
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
63+
await fs.promises.writeFile(
64+
manifestPath,
65+
JSON.stringify({
66+
name: 'foo',
67+
version: '1.2.3',
68+
private: false,
69+
}),
70+
);
71+
72+
expect(await readPackageManifest(manifestPath)).toStrictEqual({
2173
name: 'foo',
2274
version: new SemVer('1.2.3'),
2375
workspaces: [],
@@ -59,7 +111,7 @@ describe('package-manifest', () => {
59111
}),
60112
);
61113

62-
expect(await readManifest(manifestPath)).toStrictEqual({
114+
expect(await readPackageManifest(manifestPath)).toStrictEqual({
63115
name: 'foo',
64116
version: new SemVer('1.2.3'),
65117
workspaces: ['packages/*'],
@@ -100,7 +152,7 @@ describe('package-manifest', () => {
100152
}),
101153
);
102154

103-
expect(await readManifest(manifestPath)).toStrictEqual({
155+
expect(await readPackageManifest(manifestPath)).toStrictEqual({
104156
name: 'foo',
105157
version: new SemVer('1.2.3'),
106158
workspaces: [],
@@ -126,7 +178,7 @@ describe('package-manifest', () => {
126178
}),
127179
);
128180

129-
expect(await readManifest(manifestPath)).toStrictEqual({
181+
expect(await readPackageManifest(manifestPath)).toStrictEqual({
130182
name: 'foo',
131183
version: new SemVer('1.2.3'),
132184
workspaces: [],
@@ -150,7 +202,7 @@ describe('package-manifest', () => {
150202
}),
151203
);
152204

153-
await expect(readManifest(manifestPath)).rejects.toThrow(
205+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
154206
`The value of "name" in the manifest located at "${sandbox.directoryPath}" must be a non-empty string`,
155207
);
156208
});
@@ -167,7 +219,7 @@ describe('package-manifest', () => {
167219
}),
168220
);
169221

170-
await expect(readManifest(manifestPath)).rejects.toThrow(
222+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
171223
`The value of "name" in the manifest located at "${sandbox.directoryPath}" must be a non-empty string`,
172224
);
173225
});
@@ -184,7 +236,7 @@ describe('package-manifest', () => {
184236
}),
185237
);
186238

187-
await expect(readManifest(manifestPath)).rejects.toThrow(
239+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
188240
`The value of "name" in the manifest located at "${sandbox.directoryPath}" must be a non-empty string`,
189241
);
190242
});
@@ -200,7 +252,7 @@ describe('package-manifest', () => {
200252
}),
201253
);
202254

203-
await expect(readManifest(manifestPath)).rejects.toThrow(
255+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
204256
'The value of "version" in the manifest for "foo" must be a valid SemVer version string',
205257
);
206258
});
@@ -217,7 +269,7 @@ describe('package-manifest', () => {
217269
}),
218270
);
219271

220-
await expect(readManifest(manifestPath)).rejects.toThrow(
272+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
221273
'The value of "version" in the manifest for "foo" must be a valid SemVer version string',
222274
);
223275
});
@@ -235,117 +287,53 @@ describe('package-manifest', () => {
235287
}),
236288
);
237289

238-
await expect(readManifest(manifestPath)).rejects.toThrow(
290+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
239291
'The value of "workspaces" in the manifest for "foo" must be an array of non-empty strings (if present)',
240292
);
241293
});
242294
});
243295

244-
it('throws if "private" is not a boolean', async () => {
245-
await withSandbox(async (sandbox) => {
246-
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
247-
await fs.promises.writeFile(
248-
manifestPath,
249-
JSON.stringify({
250-
name: 'foo',
251-
version: '1.2.3',
252-
private: 12345,
253-
}),
254-
);
255-
256-
await expect(readManifest(manifestPath)).rejects.toThrow(
257-
'The value of "private" in the manifest for "foo" must be true or false (if present)',
258-
);
259-
});
260-
});
261-
262-
it('throws if "bundledDependencies" is not an object with string keys and string values', async () => {
263-
await withSandbox(async (sandbox) => {
264-
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
265-
await fs.promises.writeFile(
266-
manifestPath,
267-
JSON.stringify({
268-
name: 'foo',
269-
version: '1.2.3',
270-
bundledDependencies: 12345,
271-
}),
272-
);
273-
274-
await expect(readManifest(manifestPath)).rejects.toThrow(
275-
'The value of "bundledDependencies" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values',
276-
);
277-
});
278-
});
279-
280-
it('throws if "dependencies" is not an object with string keys and string values', async () => {
281-
await withSandbox(async (sandbox) => {
282-
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
283-
await fs.promises.writeFile(
284-
manifestPath,
285-
JSON.stringify({
286-
name: 'foo',
287-
version: '1.2.3',
288-
dependencies: 12345,
289-
}),
290-
);
291-
292-
await expect(readManifest(manifestPath)).rejects.toThrow(
293-
'The value of "dependencies" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values',
294-
);
295-
});
296-
});
297-
298-
it('throws if "devDependencies" is not an object with string keys and string values', async () => {
299-
await withSandbox(async (sandbox) => {
300-
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
301-
await fs.promises.writeFile(
302-
manifestPath,
303-
JSON.stringify({
304-
name: 'foo',
305-
version: '1.2.3',
306-
devDependencies: 12345,
307-
}),
308-
);
309-
310-
await expect(readManifest(manifestPath)).rejects.toThrow(
311-
'The value of "devDependencies" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values',
312-
);
313-
});
314-
});
315-
316-
it('throws if "optionalDependencies" is not an object with string keys and string values', async () => {
317-
await withSandbox(async (sandbox) => {
318-
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
319-
await fs.promises.writeFile(
320-
manifestPath,
321-
JSON.stringify({
322-
name: 'foo',
323-
version: '1.2.3',
324-
optionalDependencies: 12345,
325-
}),
326-
);
327-
328-
await expect(readManifest(manifestPath)).rejects.toThrow(
329-
'The value of "optionalDependencies" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values',
330-
);
296+
[
297+
'bundledDependencies',
298+
'dependencies',
299+
'devDependencies',
300+
'optionalDependencies',
301+
'peerDependencies',
302+
].forEach((fieldName) => {
303+
it(`throws if "${fieldName}" is not an object`, async () => {
304+
await withSandbox(async (sandbox) => {
305+
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
306+
await fs.promises.writeFile(
307+
manifestPath,
308+
JSON.stringify({
309+
name: 'foo',
310+
version: '1.2.3',
311+
[fieldName]: 12345,
312+
}),
313+
);
314+
315+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
316+
`The value of "${fieldName}" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values`,
317+
);
318+
});
331319
});
332-
});
333-
334-
it('throws if "peerDependencies" is not an object with string keys and string values', async () => {
335-
await withSandbox(async (sandbox) => {
336-
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
337-
await fs.promises.writeFile(
338-
manifestPath,
339-
JSON.stringify({
340-
name: 'foo',
341-
version: '1.2.3',
342-
peerDependencies: 12345,
343-
}),
344-
);
345320

346-
await expect(readManifest(manifestPath)).rejects.toThrow(
347-
'The value of "peerDependencies" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values',
348-
);
321+
it(`throws if "${fieldName}" is not an object with string values`, async () => {
322+
await withSandbox(async (sandbox) => {
323+
const manifestPath = path.join(sandbox.directoryPath, 'package.json');
324+
await fs.promises.writeFile(
325+
manifestPath,
326+
JSON.stringify({
327+
name: 'foo',
328+
version: '1.2.3',
329+
[fieldName]: { foo: 12345 },
330+
}),
331+
);
332+
333+
await expect(readPackageManifest(manifestPath)).rejects.toThrow(
334+
`The value of "${fieldName}" in the manifest for "foo" must be an object with non-empty string keys and non-empty string values`,
335+
);
336+
});
349337
});
350338
});
351339
});

0 commit comments

Comments
 (0)