Skip to content

Commit

Permalink
test: retry flaky pack/install test (#1316)
Browse files Browse the repository at this point in the history
Retry the pack and install test, which has several moving parts and
fails once in a blue moon. Refactored such that tests are now independent,
i.e., npm pack and webpack can be run independently.

Fixes #1315
  • Loading branch information
bcoe committed Nov 8, 2021
1 parent 6504431 commit db2f1ea
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions system-test/test.kitchen.ts
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import * as assert from 'assert';
import {describe, it, before, after} from 'mocha';
import {describe, it, afterEach} from 'mocha';
import * as execa from 'execa';
import * as fs from 'fs';
import * as mv from 'mv';
Expand All @@ -25,40 +25,51 @@ import {promisify} from 'util';
const mvp = promisify(mv) as {} as (...args: string[]) => Promise<void>;
const ncpp = promisify(ncp);
const keep = !!process.env.GALN_KEEP_TEMPDIRS;
const stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
const stagingPath = stagingDir.name;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');

let stagingDir: tmp.DirResult;
let stagingPath: string;
async function packAndInstall() {
stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
stagingPath = stagingDir.name;
await execa('npm', ['pack'], {stdio: 'inherit'});
const tarball = `${pkg.name}-${pkg.version}.tgz`;
// stagingPath can be on another filesystem so fs.rename() will fail
// with EXDEV, hence we use `mv` module here.
await mvp(tarball, `${stagingPath}/google-auth-library.tgz`);
await ncpp('system-test/fixtures/kitchen', `${stagingPath}/`);
await execa('npm', ['install'], {cwd: `${stagingPath}/`, stdio: 'inherit'});
}

describe('pack and install', () => {
/**
* Create a staging directory with temp fixtures used to test on a fresh
* application.
*/
before('should be able to use the d.ts', async function () {
it('should be able to use the d.ts', async function () {
// npm, once in a blue moon, fails during pack process. If this happens,
// we should be safe to retry.
//this.retries(3);
this.timeout(40000);
console.log(`${__filename} staging area: ${stagingPath}`);
await execa('npm', ['pack'], {stdio: 'inherit'});
const tarball = `${pkg.name}-${pkg.version}.tgz`;
// stagingPath can be on another filesystem so fs.rename() will fail
// with EXDEV, hence we use `mv` module here.
await mvp(tarball, `${stagingPath}/google-auth-library.tgz`);
await ncpp('system-test/fixtures/kitchen', `${stagingPath}/`);
await execa('npm', ['install'], {cwd: `${stagingPath}/`, stdio: 'inherit'});
await packAndInstall();
});

it('should be able to webpack the library', async () => {
it('should be able to webpack the library', async function () {
this.retries(3);
this.timeout(40000);
await packAndInstall();
// we expect npm install is executed in the before hook
await execa('npx', ['webpack'], {cwd: `${stagingPath}/`, stdio: 'inherit'});
const bundle = path.join(stagingPath, 'dist', 'bundle.min.js');
const stat = fs.statSync(bundle);
assert(stat.size < 256 * 1024);
}).timeout(20000);
});

/**
* CLEAN UP - remove the staging directory when done.
*/
after('cleanup staging', () => {
afterEach('cleanup staging', () => {
if (!keep) {
stagingDir.removeCallback();
}
Expand Down

0 comments on commit db2f1ea

Please sign in to comment.