Skip to content

Commit b0ddc2c

Browse files
authored
Merge ac415b1 into 5dac8b3
2 parents 5dac8b3 + ac415b1 commit b0ddc2c

File tree

6 files changed

+100
-101
lines changed

6 files changed

+100
-101
lines changed

config/mocha.browser.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
# karma runner supports.
2222
# This file is not converted to .mocharc.js format because karma-mocha doesn't work with it.
2323

24-
--timeout 20000
24+
--timeout 60000
2525
--retry 3

packages/firestore/test/integration/api/aggregation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ apiDescribe('Count queries', persistence => {
7373
where('author', '==', 'authorA')
7474
).withConverter(throwingConverter);
7575
const snapshot = await getCountFromServer(query_);
76-
expect(snapshot.data().count).to.equal(1);
76+
expect(snapshot.data().count).to.equal(42);
7777
});
7878
});
7979

packages/firestore/test/integration/remote/stream.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ it('token is not invalidated once the stream is healthy', () => {
291291
new FirestoreError(Code.UNAUTHENTICATED, '')
292292
);
293293
await streamListener.awaitCallback('close');
294-
expect(credentials.observedStates).to.deep.equal(['getToken']);
294+
expect(credentials.observedStates).to.deep.equal(['getTokenZZYZX']);
295295
}, credentials);
296296
});
297297

scripts/ci-test/build_changed.ts

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,36 @@ async function buildForTests(
6363
config: TestConfig,
6464
{ buildAll = false }: Options
6565
) {
66-
try {
67-
const testTasks = filterTasks(await getTestTasks(), config);
68-
// print tasks for info
69-
logTasks(testTasks);
70-
if (testTasks.length === 0) {
71-
console.log(chalk`{green No test tasks. Skipping all builds }`);
72-
return;
73-
}
66+
const testTasks = filterTasks(await getTestTasks(), config);
67+
// print tasks for info
68+
logTasks(testTasks);
69+
if (testTasks.length === 0) {
70+
console.log(chalk`{green No test tasks. Skipping all builds }`);
71+
return;
72+
}
7473

75-
// build all and return
76-
if (buildAll) {
77-
await spawn('yarn', ['build'], { stdio: 'inherit', cwd: root });
78-
return;
79-
}
74+
// build all and return
75+
if (buildAll) {
76+
await spawn('yarn', ['build'], { stdio: 'inherit', cwd: root });
77+
return;
78+
}
8079

81-
const lernaCmd = ['lerna', 'run'];
82-
console.log(chalk`{blue Running build in:}`);
83-
for (const task of testTasks) {
84-
if (task.reason === TestReason.Changed) {
85-
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
86-
} else if (task.reason === TestReason.Dependent) {
87-
console.log(
88-
chalk`{yellow ${task.pkgName} (depends on modified files)}`
89-
);
90-
} else {
91-
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
92-
}
93-
lernaCmd.push('--scope');
94-
lernaCmd.push(task.pkgName);
80+
const lernaCmd = ['lerna', 'run'];
81+
console.log(chalk`{blue Running build in:}`);
82+
for (const task of testTasks) {
83+
if (task.reason === TestReason.Changed) {
84+
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
85+
} else if (task.reason === TestReason.Dependent) {
86+
console.log(
87+
chalk`{yellow ${task.pkgName} (depends on modified files)}`
88+
);
89+
} else {
90+
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
9591
}
96-
97-
lernaCmd.push('--include-dependencies', 'build');
98-
await spawn('npx', lernaCmd, { stdio: 'inherit', cwd: root });
99-
} catch (e) {
100-
console.error(chalk`{red ${e}}`);
101-
process.exit(1);
92+
lernaCmd.push('--scope');
93+
lernaCmd.push(task.pkgName);
10294
}
95+
96+
lernaCmd.push('--include-dependencies', 'build');
97+
await spawn('npx', lernaCmd, { stdio: 'inherit', cwd: root });
10398
}

scripts/ci-test/test_changed.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,31 @@ const config = testConfig[inputTestConfigName]!;
4949
runTests(config);
5050

5151
async function runTests(config: TestConfig) {
52-
try {
53-
const testTasks = filterTasks(await getTestTasks(), config);
52+
const testTasks = filterTasks(await getTestTasks(), config);
5453

55-
// print tasks for info
56-
logTasks(testTasks);
57-
if (testTasks.length === 0) {
58-
chalk`{green No test tasks. Skipping all tests }`;
59-
process.exit(0);
60-
}
54+
// print tasks for info
55+
logTasks(testTasks);
56+
if (testTasks.length === 0) {
57+
chalk`{green No test tasks. Skipping all tests }`;
58+
process.exit(0);
59+
}
6160

62-
const lernaCmd = ['lerna', 'run', '--concurrency', '4'];
63-
console.log(chalk`{blue Running tests in:}`);
64-
for (const task of testTasks) {
65-
if (task.reason === TestReason.Changed) {
66-
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
67-
} else if (task.reason === TestReason.Dependent) {
68-
console.log(
69-
chalk`{yellow ${task.pkgName} (depends on modified files)}`
70-
);
71-
} else {
72-
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
73-
}
74-
lernaCmd.push('--scope');
75-
lernaCmd.push(task.pkgName);
61+
const lernaCmd = ['lerna', 'run', '--concurrency', '4'];
62+
console.log(chalk`{blue Running tests in:}`);
63+
for (const task of testTasks) {
64+
if (task.reason === TestReason.Changed) {
65+
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
66+
} else if (task.reason === TestReason.Dependent) {
67+
console.log(
68+
chalk`{yellow ${task.pkgName} (depends on modified files)}`
69+
);
70+
} else {
71+
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
7672
}
77-
78-
lernaCmd.push(testCommand);
79-
await spawn('npx', lernaCmd, { stdio: 'inherit', cwd: root });
80-
process.exit(0);
81-
} catch (e) {
82-
console.error(chalk`{red ${e}}`);
83-
process.exit(1);
73+
lernaCmd.push('--scope');
74+
lernaCmd.push(task.pkgName);
8475
}
76+
77+
lernaCmd.push(testCommand);
78+
await spawn('npx', lernaCmd, { stdio: 'inherit', cwd: root });
8579
}

scripts/run_tests_in_ci.js

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
const yargs = require('yargs');
1919
const path = require('path');
20-
const { spawn } = require('child-process-promise');
21-
const { writeFileSync } = require('fs');
20+
const { spawn } = require('node:child_process');
21+
const fs = require('node:fs');
2222

2323
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
2424
// Maps the packages where we should not run `test:all` and instead isolate the cross-browser tests.
@@ -30,16 +30,17 @@ const crossBrowserPackages = {
3030
'packages/firestore-compat': 'test:browser'
3131
};
3232

33-
function writeLogs(status, name, logText) {
34-
const safeName = name.replace(/@/g, 'at_').replace(/\//g, '_');
35-
writeFileSync(path.join(LOGDIR, `${safeName}-ci-log.txt`), logText, {
36-
encoding: 'utf8'
33+
function getPathSafeName(name) {
34+
return name.replace(/@/g, 'at_').replace(/\//g, '_');
35+
}
36+
37+
async function printFile(path) {
38+
const readStream = fs.createReadStream(path);
39+
readStream.pipe(process.stdout);
40+
await new Promise((resolve, reject) => {
41+
readStream.once('end', resolve);
42+
readStream.once('error', reject);
3743
});
38-
writeFileSync(
39-
path.join(LOGDIR, `${safeName}-ci-summary.txt`),
40-
`${status}: ${name}`,
41-
{ encoding: 'utf8' }
42-
);
4344
}
4445

4546
const argv = yargs.options({
@@ -60,34 +61,43 @@ const argv = yargs.options({
6061
let scriptName = argv.s;
6162
const dir = path.resolve(myPath);
6263
const { name } = require(`${dir}/package.json`);
64+
const testOutputFile = path.join(
65+
LOGDIR,
66+
`${getPathSafeName(name)}-ci-log.txt`
67+
);
6368

64-
let stdout = '';
65-
let stderr = '';
66-
try {
67-
if (process.env?.BROWSERS) {
68-
for (const package in crossBrowserPackages) {
69-
if (dir.endsWith(package)) {
70-
scriptName = crossBrowserPackages[package];
71-
}
69+
if (process.env?.BROWSERS) {
70+
for (const package in crossBrowserPackages) {
71+
if (dir.endsWith(package)) {
72+
scriptName = crossBrowserPackages[package];
7273
}
7374
}
74-
const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);
75+
}
76+
77+
const testOutputFileHandle = fs.openSync(testOutputFile, 'w');
78+
const testProcess = spawn('yarn', ['--cwd', dir, scriptName], {
79+
stdio: ['inherit', testOutputFileHandle, testOutputFileHandle]
80+
});
81+
82+
const exitCode = await new Promise((resolve, reject) => {
83+
testProcess.once('close', resolve);
84+
testProcess.once('error', reject);
85+
}).finally(() => {
86+
fs.closeSync(testOutputFileHandle);
87+
});
7588

76-
testProcess.childProcess.stdout.on('data', data => {
77-
stdout += data.toString();
78-
});
79-
testProcess.childProcess.stderr.on('data', data => {
80-
stderr += data.toString();
81-
});
89+
const resultStr = exitCode === 0 ? 'Success' : 'Failure';
90+
console.log(`${resultStr}: ${name}`);
91+
await printFile(testOutputFile);
8292

83-
await testProcess;
84-
console.log('Success: ' + name);
85-
writeLogs('Success', name, stdout + '\n' + stderr);
86-
} catch (e) {
87-
console.error('Failure: ' + name);
88-
console.log(stdout);
89-
console.error(stderr);
90-
writeLogs('Failure', name, stdout + '\n' + stderr);
91-
process.exit(1);
92-
}
93+
fs.writeFileSync(
94+
path.join(LOGDIR, `${getPathSafeName(name)}-ci-summary.txt`),
95+
`${resultStr}: ${name}`,
96+
{ encoding: 'utf8' }
97+
);
98+
99+
// NOTE: Set `process.exitCode` rather than calling `process.exit()` because
100+
// the latter will exit forcefully even if stdout/stderr have not been fully
101+
// flushed, leading to truncated output.
102+
process.exitCode = exitCode;
93103
})();

0 commit comments

Comments
 (0)