Skip to content

Commit 80448d4

Browse files
author
Brian Vaughn
committed
Add release script snapshot test
1 parent 8ba1f03 commit 80448d4

File tree

4 files changed

+935
-1
lines changed

4 files changed

+935
-1
lines changed

scripts/release/prepare-stable-commands/check-out-packages.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
'use strict';
44

55
const {exec} = require('child-process-promise');
6+
const {existsSync} = require('fs');
67
const {join} = require('path');
78
const {logPromise} = require('../utils');
89
const theme = require('../theme');
910

10-
const run = async ({cwd, packages, version}) => {
11+
const run = async ({cwd, local, packages, version}) => {
12+
if (local) {
13+
// Sanity test
14+
if (!existsSync(join(cwd, 'build', 'node_modules', 'react'))) {
15+
console.error(theme.error`No local build exists.`);
16+
process.exit(1);
17+
}
18+
return;
19+
}
20+
1121
// Cleanup from previous builds
1222
await exec(`rm -rf ./build/node_modules*`, {cwd});
1323
await exec(`mkdir ./build/node_modules`, {cwd});

scripts/release/prepare-stable-commands/parse-params.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ const commandLineArgs = require('command-line-args');
66
const commandLineUsage = require('command-line-usage');
77

88
const paramDefinitions = [
9+
{
10+
name: 'local',
11+
type: Boolean,
12+
description:
13+
'Skip NPM and use the build already present in "build/node_modules".',
14+
defaultValue: false,
15+
},
916
{
1017
name: 'version',
1118
type: String,

scripts/release/test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const {exec, spawn} = require('child-process-promise');
6+
const clear = require('clear');
7+
const {join} = require('path');
8+
const {readFileSync} = require('fs');
9+
const theme = require('./theme');
10+
const {printDiff} = require('./utils');
11+
12+
const cwd = join(__dirname, '..', '..');
13+
14+
const run = async () => {
15+
const defaultOptions = {
16+
cwd,
17+
stdio: [process.stdin, process.stdout, process.stderr],
18+
env: process.env,
19+
};
20+
21+
try {
22+
// Start with a known build/revision:
23+
// https://circleci.com/gh/facebook/react/12707
24+
await spawn(
25+
'node',
26+
['./scripts/release/prepare-canary.js', '--build=12707'],
27+
defaultOptions
28+
);
29+
await spawn(
30+
'node',
31+
[
32+
'./scripts/release/prepare-stable.js',
33+
'--version=0.0.0-b3d1a81a9',
34+
'--local',
35+
],
36+
defaultOptions
37+
);
38+
39+
const beforeContents = readFileSync(
40+
'scripts/release/test.snapshot',
41+
'utf-8',
42+
{cwd}
43+
);
44+
await exec('cp build/temp.diff scripts/release/test.snapshot');
45+
const afterContents = readFileSync(
46+
'scripts/release/test.snapshot',
47+
'utf-8',
48+
{cwd}
49+
);
50+
51+
clear();
52+
53+
if (beforeContents === afterContents) {
54+
console.log(theme.header`Snapshot test passed.`);
55+
} else {
56+
printDiff('scripts/release/test.snapshot', beforeContents, afterContents);
57+
console.log();
58+
console.error(theme.error('Snapshot test failed!'));
59+
console.log();
60+
console.log(
61+
'If this failure was expected, please update the contents of the snapshot file:'
62+
);
63+
console.log(
64+
theme` {command git add} {path scripts/release/test.snapshot}`
65+
);
66+
console.log(
67+
theme` {command git commit -m "Updating release script snapshot file."}`
68+
);
69+
process.exit(1);
70+
}
71+
} catch (error) {
72+
console.error(theme.error(error));
73+
process.exit(1);
74+
}
75+
};
76+
77+
run();

0 commit comments

Comments
 (0)