Skip to content

Commit ca4cddf

Browse files
christianalfoniCompuIves
authored andcommitted
add script to test prs (codesandbox#2790)
* add script to test prs * do not throw on stderror, it breaks initial checkout * do not install deps, as they rarely change * better logs * merge master before creating PR branch
1 parent e62f02a commit ca4cddf

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"start:test": "lerna run start:test --scope app --stream",
5757
"start:vscode": "cross-env VSCODE=1 yarn start:fast & cd standalone-packages/monaco-editor && yarn simpleserver & cd standalone-packages/vscode && yarn watch",
5858
"test": "lerna run test --ignore codesandbox-browserfs",
59+
"test:pr": "node testpr-script",
5960
"test:ci": "lerna run test --ignore codesandbox-browserfs -- --ci --testResultsProcessor=\"jest-junit\" ",
6061
"test:integrations": "lerna exec --scope app --stream -- yarn test:integrations",
6162
"test:jest-lite": "lerna exec --scope app --stream -- yarn run test jest-lite --watch --coverage",
@@ -86,7 +87,8 @@
8687
"lint-staged": "^9.2.5",
8788
"prettier": "1.17.0",
8889
"pretty-quick": "^1.10.0",
89-
"typescript": "3.6.3"
90+
"typescript": "3.6.3",
91+
"username": "^5.1.0"
9092
},
9193
"husky": {
9294
"hooks": {

testpr-script.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const { spawn } = require('child_process');
2+
const { argv } = require('yargs');
3+
const username = require('username');
4+
5+
const id = argv._[0];
6+
7+
function spawnPromise(command, args) {
8+
return new Promise((resolve, reject) => {
9+
const p = spawn(command, args);
10+
11+
p.stdout.on('data', data => {
12+
// eslint-disable-next-line
13+
console.log(data.toString());
14+
});
15+
16+
p.stderr.on('data', data => {
17+
console.error(data.toString());
18+
});
19+
20+
p.on('exit', code => {
21+
if (code === 0) {
22+
resolve();
23+
} else {
24+
reject();
25+
}
26+
});
27+
});
28+
}
29+
30+
async function test(prId) {
31+
const branchName = `pr-${username.sync()}-${prId}`;
32+
33+
Promise.resolve()
34+
.then(() => spawnPromise('git', ['checkout', 'master']))
35+
.then(() => spawnPromise('git', ['pull']))
36+
.then(() =>
37+
spawnPromise('git', [
38+
'fetch',
39+
'origin',
40+
`pull/${prId}/head:${branchName}`,
41+
])
42+
)
43+
.then(() => spawnPromise('git', ['checkout', branchName]))
44+
.then(() => spawnPromise('git', ['merge', 'master']))
45+
.then(() => spawnPromise('yarn', ['build:deps']))
46+
.catch(() => {
47+
console.error(
48+
'Something wrong happened building the deps, maybe missing a new package added. Please install and run build:deps manually before continuing'
49+
);
50+
});
51+
}
52+
53+
if (id && Number(id)) {
54+
test(Number(id));
55+
} else {
56+
throw new Error('You have to pass the ID of a PR, ex: yarn test:pr 1234');
57+
}

yarn.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17042,7 +17042,7 @@ mem@^1.1.0:
1704217042
dependencies:
1704317043
mimic-fn "^1.0.0"
1704417044

17045-
mem@^4.0.0:
17045+
mem@^4.0.0, mem@^4.3.0:
1704617046
version "4.3.0"
1704717047
resolved "https://registry.yarnpkg.com/mem/-/mem-4.3.0.tgz#461af497bc4ae09608cdb2e60eefb69bff744178"
1704817048
integrity sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==
@@ -25865,6 +25865,14 @@ user-home@^1.1.1:
2586525865
version "1.1.1"
2586625866
resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"
2586725867

25868+
username@^5.1.0:
25869+
version "5.1.0"
25870+
resolved "https://registry.yarnpkg.com/username/-/username-5.1.0.tgz#a7f9325adce2d0166448cdd55d4985b1360f2508"
25871+
integrity sha512-PCKbdWw85JsYMvmCv5GH3kXmM66rCd9m1hBEDutPNv94b/pqCMT4NtcKyeWYvLFiE8b+ha1Jdl8XAaUdPn5QTg==
25872+
dependencies:
25873+
execa "^1.0.0"
25874+
mem "^4.3.0"
25875+
2586825876
utif@^2.0.1:
2586925877
version "2.0.1"
2587025878
resolved "https://registry.yarnpkg.com/utif/-/utif-2.0.1.tgz#9e1582d9bbd20011a6588548ed3266298e711759"

0 commit comments

Comments
 (0)