Skip to content

Commit f08cd65

Browse files
test: Improve Kitchen Test Logging (#1914)
* test: Improve Kitchen Test Logging - Adds missing STDERR logging for improved debugging, which was missing for a while - Removes `execa`, as it is unneeded and outdated * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: add 'error' event handle * test: documentation --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 12f2c87 commit f08cd65

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,19 +1041,19 @@ class CustomSupplier implements SubjectTokenSupplier {
10411041
}
10421042

10431043
const clientOptions = {
1044-
audience: '//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
1044+
audience: '//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
10451045
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', // Set the subject token type.
10461046
subject_token_supplier: new CustomSupplier() // Set the custom supplier.
10471047
}
10481048

10491049
const client = new CustomSupplier(clientOptions);
10501050
```
10511051

1052-
Where the audience is: `//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
1052+
Where the audience is: `//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID`
10531053

10541054
Where the following variables need to be substituted:
10551055

1056-
* `WORKFORCE_POOL_ID`: The worforce pool ID.
1056+
* `$WORKFORCE_POOL_ID`: The worforce pool ID.
10571057
* `$PROVIDER_ID`: The provider ID.
10581058

10591059
and the workforce pool user project is the project number associated with the [workforce pools user project](https://cloud.google.com/iam/docs/workforce-identity-federation#workforce-pools-user-project).

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"chai": "^4.2.0",
3939
"cheerio": "1.0.0-rc.12",
4040
"codecov": "^3.0.2",
41-
"execa": "^5.0.0",
4241
"gts": "^5.0.0",
4342
"is-docker": "^2.0.0",
4443
"jsdoc": "^4.0.0",

system-test/test.kitchen.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
import * as assert from 'assert';
1616
import {describe, it, afterEach} from 'mocha';
17-
import * as execa from 'execa';
1817
import * as fs from 'fs';
1918
import * as mv from 'mv';
2019
import {ncp} from 'ncp';
2120
import * as os from 'os';
2221
import * as path from 'path';
2322
import {promisify} from 'util';
23+
import {spawn} from 'child_process';
2424

2525
const mvp = promisify(mv) as {} as (...args: string[]) => Promise<void>;
2626
const ncpp = promisify(ncp);
@@ -29,18 +29,39 @@ const keep = !!process.env.GALN_KEEP_TEMPDIRS;
2929
const pkg = require('../../package.json');
3030

3131
let stagingDir: string;
32+
33+
/**
34+
* Spawns and runs a command asynchronously.
35+
*
36+
* @param params params to pass to {@link spawn}
37+
*/
38+
async function run(...params: Parameters<typeof spawn>) {
39+
const command = spawn(...params);
40+
41+
await new Promise<void>((resolve, reject) => {
42+
// Unlike `exec`/`execFile`, this keeps the order of STDOUT/STDERR in case they were interweaved;
43+
// making it easier to debug and follow along.
44+
command.stdout?.on('data', console.log);
45+
command.stderr?.on('data', console.error);
46+
command.on('close', (code, signal) => {
47+
return code === 0 ? resolve() : reject({code, signal});
48+
});
49+
command.on('error', reject);
50+
});
51+
}
52+
3253
async function packAndInstall() {
3354
stagingDir = await fs.promises.mkdtemp(
3455
path.join(os.tmpdir(), 'google-auth-library-nodejs-pack-')
3556
);
3657

37-
await execa('npm', ['pack'], {stdio: 'inherit'});
58+
await run('npm', ['pack'], {});
3859
const tarball = `${pkg.name}-${pkg.version}.tgz`;
3960
// stagingPath can be on another filesystem so fs.rename() will fail
4061
// with EXDEV, hence we use `mv` module here.
4162
await mvp(tarball, `${stagingDir}/google-auth-library.tgz`);
4263
await ncpp('system-test/fixtures/kitchen', `${stagingDir}/`);
43-
await execa('npm', ['install'], {cwd: `${stagingDir}/`, stdio: 'inherit'});
64+
await run('npm', ['install'], {cwd: `${stagingDir}/`});
4465
}
4566

4667
describe('pack and install', () => {
@@ -61,10 +82,10 @@ describe('pack and install', () => {
6182
this.timeout(40000);
6283
await packAndInstall();
6384
// we expect npm install is executed in the before hook
64-
await execa('npx', ['webpack'], {cwd: `${stagingDir}/`, stdio: 'inherit'});
85+
await run('npx', ['webpack'], {cwd: `${stagingDir}/`});
6586
const bundle = path.join(stagingDir, 'dist', 'bundle.min.js');
6687
// ensure it is a non-empty bundle
67-
assert(fs.statSync(bundle).size);
88+
assert(fs.statSync(bundle).size, 'Size should not be empty');
6889
});
6990

7091
/**

0 commit comments

Comments
 (0)