forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-behavior.js
97 lines (83 loc) · 2.51 KB
/
test-behavior.js
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
'use strict';
const args = process.argv.slice(2);
const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const spawn = require('cross-spawn');
const applicationPath = args.pop();
const applicationPackageJson = path.resolve(applicationPath, 'package.json');
const applicationSrc = path.resolve(applicationPath, 'src');
const applicationModules = path.resolve(applicationPath, 'node_modules');
const fixturePath = path.resolve(__dirname, '..', 'fixtures', 'behavior');
const fixtures = fs
.readdirSync(fixturePath)
.map(fixture => path.resolve(fixturePath, fixture))
.filter(path => fs.lstatSync(path).isDirectory);
const packageContents = require(applicationPackageJson);
function install({ root }) {
spawn.sync('yarnpkg', ['--cwd', root, 'install'], { cwd: root });
}
function startApp({ root }) {
const output = spawn
.sync('yarnpkg', ['start', '--smoke-test'], { cwd: root })
.output.join('');
if (!/Compiled successfully/.test(output)) {
throw new Error(output);
}
console.log('\t = application started: ', output);
}
function buildApp({ root }) {
const output = spawn
.sync('yarnpkg', ['build'], { cwd: root })
.output.join('');
if (!/Compiled successfully/.test(output)) {
throw new Error(output);
}
console.log('\t = application built: ', output);
}
console.log(`=> checking ${fixtures.length} fixtures`);
for (const fixture of fixtures) {
const {
name,
description,
dependencies,
devDependencies,
} = require(path.resolve(fixture, 'package.json'));
console.log(`\t * checking fixture ${name}`);
console.log(`\t ... this fixture: ${description}`);
fs.emptyDirSync(applicationSrc);
fs.emptyDirSync(applicationModules);
fs.copySync(path.resolve(fixture, 'src'), applicationSrc);
try {
fs.writeJsonSync(
applicationPackageJson,
Object.assign({}, packageContents, {
dependencies: Object.assign(
{},
packageContents.dependencies,
dependencies
),
devDependencies: Object.assign(
{},
packageContents.devDependencies,
devDependencies
),
}),
{
spaces: 2,
EOL: os.EOL,
}
);
install({ root: applicationPath });
startApp({ root: applicationPath });
buildApp({ root: applicationPath });
} catch (e) {
console.error(`\t ! failed on ${name}:`);
throw e;
} finally {
fs.writeJsonSync(applicationPackageJson, packageContents, {
spaces: 2,
EOL: os.EOL,
});
}
}