-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrunfile.js
198 lines (161 loc) · 5.72 KB
/
runfile.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
const { run } = require('runjs');
const fs = require('fs-extra');
const symlinkDir = require('symlink-dir');
const pkgManager = process.env.CIRCLECI ? 'npm' : 'yarn';
const c = {
build: 'babel src --out-dir .',
buildTest: 'babel src --out-dir plugins/gatsby-plugin-purgecss',
pack: 'npm pack',
installBuild: `cd test_build && ${pkgManager} install && cd ..`,
listBuild: `cd test_build && ${pkgManager} list --depth=0 gatsby less node-sass gatsby-plugin-sass gatsby-plugin-less gatsby-plugin-stylus && cd ..`,
installTailwind: `cd test_tailwind && ${pkgManager} install && cd ..`,
listTailwind: `cd test_tailwind && ${pkgManager} list --depth=0 gatsby tailwindcss gatsby-plugin-postcss && cd ..`,
buildTestBuild: 'cd test_build && npm run build && cd ..',
buildTestTailwindBuild: 'cd test_tailwind && npm run build && cd ..',
jestCoverage: 'jest --ci --coverage',
jestUnit: 'jest unit',
jestE2E: 'jest build',
jestTailwind: 'jest tailwind',
install(filename) {
if (pkgManager === 'npm')
return `cd test_build && npm install ../${filename} && cd ..`;
return `cd test_build && yarn cache clean "gatsby-plugin-purgecss" && yarn add -D file:../${filename} && cd ..`;
},
installInTailwind(filename) {
if (pkgManager === 'npm')
return `cd test_tailwind && npm install ../${filename} && cd ..`;
return `cd test_tailwind && yarn cache clean "gatsby-plugin-purgecss" && yarn add -D file:../${filename} && cd ..`;
}
};
function test_ci() {
console.log('\nBuilding');
run(c.build);
console.log('\nCreating npm package');
run(c.pack);
console.log('\nInstalling test_build packages');
run(c.installBuild);
run(c.listBuild);
console.log('\nInstalling gatsby-plugin-purgecss package');
let files = fs.readdirSync('.', 'utf8');
files = files.filter(file => {
return file.includes('gatsby-plugin-purgecss');
});
run(c.install(files[0]));
console.log('\nRunning gatsby build in test_build');
run(c.buildTestBuild);
console.log('\nInstalling test_build packages');
run(c.installTailwind);
run(c.listTailwind);
console.log('\nInstalling gatsby-plugin-purgecss package');
run(c.installInTailwind(files[0]));
console.log('\nRunning gatsby build in test_tailwind');
run(c.buildTestTailwindBuild);
console.log('\nRunning tests with coverage');
run(c.jestCoverage);
}
function testbuild() {
console.log('\nRunning unit tests');
run(c.jestUnit);
console.log('\nBuilding to plugins folder');
run(c.buildTest);
console.log('\nMaking an empty package.json for plugin');
try {
fs.copySync('./empty.json', 'plugins/gatsby-plugin-purgecss/package.json');
console.log('\nSuccess');
} catch (err) {
console.error(err);
}
console.log('\nLinking node_modules and plugins folder to test_build');
symlinkDir('node_modules', 'test_build/node_modules/')
.then(result => symlinkDir('plugins', 'test_build/plugins/'))
.then(result => {
console.log('\nSuccess');
console.log('\nRunning gatsby build in test_build');
run(c.buildTestBuild);
console.log('\nRunning e2e tests');
run(c.jestE2E);
})
.catch(err => console.error(err));
}
function test() {
console.log('\nRunning unit tests');
run(c.jestUnit);
console.log('\nBuilding to plugins folder');
run(c.buildTest);
console.log('\nMaking an empty package.json for plugin');
try {
fs.copySync('./empty.json', 'plugins/gatsby-plugin-purgecss/package.json');
console.log('\nSuccess');
} catch (err) {
console.error(err);
}
console.log('\nLinking node_modules and plugins folder to test_build');
symlinkDir('node_modules', 'test_build/node_modules/')
.then(result => symlinkDir('plugins', 'test_build/plugins/'))
.then(result => {
console.log('\nSuccess');
console.log('\nRunning gatsby build in test_build');
run(c.buildTestBuild);
console.log('\nRunning e2e tests');
run(c.jestE2E);
})
.then(() => {
console.log('\nLinking node_modules and plugins folder to testtailwind');
return symlinkDir('node_modules', 'test_tailwind/node_modules/');
})
.then(result => symlinkDir('plugins', 'test_tailwind/plugins/'))
.then(result => {
console.log('\nSuccess');
console.log('\nRunning gatsby build in test_tailwind');
run(c.buildTestTailwindBuild);
console.log('\nRunning e2e tests');
run(c.jestTailwind);
})
.catch(err => console.error(err));
}
function testtailwind() {
console.log('\nRunning unit tests');
run(c.jestUnit);
console.log('\nBuilding to plugins folder');
run(c.buildTest);
console.log('\nMaking an empty package.json for plugin');
try {
fs.copySync('./empty.json', 'plugins/gatsby-plugin-purgecss/package.json');
console.log('\nSuccess');
} catch (err) {
console.error(err);
}
console.log('\nLinking node_modules and plugins folder to test_tailwind');
symlinkDir('node_modules', 'test_tailwind/node_modules/')
.then(result => symlinkDir('plugins', 'test_tailwind/plugins/'))
.then(result => {
console.log('\nSuccess');
console.log('\nRunning gatsby build in test_tailwind');
run(c.buildTestTailwindBuild);
console.log('\nRunning e2e tests');
run(c.jestTailwind);
})
.catch(err => console.error(err));
}
function teste2e() {
console.log('\nBuilding to plugins folder');
run(c.buildTest);
console.log('\nRunning gatsby build in test_build');
run(c.buildTestBuild);
console.log('\nRunning e2e tests');
run(c.jestE2E);
}
function testdevelop() {
console.log('\nBuilding to plugins folder');
run(c.buildTest);
console.log('\nRunning gatsby build in test_build');
run(c.buildTestBuild);
}
module.exports = {
test_ci,
teste2e,
testbuild,
testtailwind,
testdevelop,
test
};