Skip to content

Commit

Permalink
refactor: drop pify dependency (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and bcoe committed May 10, 2019
1 parent 70b1243 commit 3a4ff77
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 48 deletions.
2 changes: 0 additions & 2 deletions package.json
Expand Up @@ -64,7 +64,6 @@
"@types/nock": "^10.0.0",
"@types/node": "^10.0.8",
"@types/nunjucks": "^3.0.0",
"@types/pify": "^3.0.2",
"@types/qs": "^6.5.1",
"@types/rimraf": "^2.0.2",
"@types/source-map-support": "^0.5.0",
Expand Down Expand Up @@ -92,7 +91,6 @@
"nyc": "^14.0.0",
"opn": "^5.3.0",
"p-queue": "^5.0.0",
"pify": "^4.0.0",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"server-destroy": "^1.0.1",
Expand Down
61 changes: 20 additions & 41 deletions system-test/kitchen.test.ts
Expand Up @@ -17,61 +17,40 @@
import * as cp from 'child_process';
import * as mv from 'mv';
import {ncp} from 'ncp';
import * as pify from 'pify';
import {promisify} from 'util';
import * as tmp from 'tmp';

const mvp = pify(mv);
const ncpp = pify(ncp);
const mvp = promisify(mv);
const ncpp = promisify(ncp);
const keep = !!process.env.GANC_KEEP_TEMPDIRS;
const stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
const stagingPath = stagingDir.name;
const pkg = require('../../package.json');

const spawnp = (
command: string,
args: string[],
options: cp.SpawnOptions = {}
): Promise<void> => {
return new Promise((resolve, reject) => {
cp.spawn(
command,
args,
Object.assign(options, {stdio: 'inherit', shell: true})
)
.on('close', (code, signal) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Spawn failed with an exit code of ${code}`));
}
})
.on('error', err => {
reject(err);
});
});
};
const spawnOpts: cp.SpawnSyncOptions = {stdio: 'inherit', shell: true};

/**
* Create a staging directory with temp fixtures used
* to test on a fresh application.
* Create a staging directory with temp fixtures used to test on a fresh application.
*/

describe('kitchen sink', async () => {
it('should be able to use the d.ts', async () => {
console.log(`${__filename} staging area: ${stagingPath}`);
await spawnp('npm', ['pack']);
cp.spawnSync('npm', ['pack'], spawnOpts);
const tarball = `${pkg.name}-${pkg.version}.tgz`;
await mvp(tarball, `${stagingPath}/googleapis.tgz`);
await (mvp as Function)(tarball, `${stagingPath}/googleapis.tgz`);
await ncpp('test/fixtures/kitchen', `${stagingPath}/`);
await spawnp('npm', ['install'], {cwd: `${stagingPath}/`});
cp.spawnSync(
'npm',
['install'],
Object.assign({cwd: `${stagingPath}/`}, spawnOpts)
);
}).timeout(80000);
});

/**
* CLEAN UP - remove the staging directory when done.
*/
after('cleanup staging', async () => {
if (!keep) {
stagingDir.removeCallback();
}
/**
* CLEAN UP - remove the staging directory when done.
*/
after('cleanup staging', async () => {
if (!keep) {
stagingDir.removeCallback();
}
});
});
4 changes: 1 addition & 3 deletions test/samples/test.samples.auth.ts
Expand Up @@ -15,10 +15,8 @@ import * as assert from 'assert';
import * as fs from 'fs';
import * as nock from 'nock';
import * as path from 'path';
import * as pify from 'pify';

import {Utils} from './../utils';
const fsp = pify(fs);

nock.disableNetConnect();

Expand All @@ -44,7 +42,7 @@ describe('Auth samples', () => {
const realPath = path.join(__dirname, '../../../samples/jwt.keys.json');
const exists = fs.existsSync(realPath);
if (!exists) {
await fsp.symlink(fakePath, realPath);
fs.symlinkSync(fakePath, realPath);
}
const data = await samples.jwt.runSample();
assert(data);
Expand Down
3 changes: 1 addition & 2 deletions test/test.media.ts
Expand Up @@ -15,7 +15,6 @@ import * as assert from 'assert';
import * as fs from 'fs';
import * as nock from 'nock';
import * as path from 'path';
import * as pify from 'pify';
import {URL} from 'url';

import {drive_v2, gmail_v1, GoogleApis} from '../src';
Expand Down Expand Up @@ -114,7 +113,7 @@ describe('Media', () => {
)
.reply(200);
const fileName = path.join(__dirname, '../../test/fixtures/mediabody.txt');
const fileSize = (await pify(fs.stat)(fileName)).size;
const fileSize = fs.statSync(fileName).size;
const google = new GoogleApis();
const youtube = google.youtube('v3');
const progressEvents = new Array<number>();
Expand Down

0 comments on commit 3a4ff77

Please sign in to comment.