Skip to content

Commit

Permalink
fix: Make tests green again -- update commander version + minor adjus…
Browse files Browse the repository at this point in the history
…tments. Also fix cleanup of tests to correctly restore credentials
  • Loading branch information
sqrrrl committed May 6, 2021
1 parent 0c9c773 commit d526a9f
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 36 deletions.
174 changes: 166 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -68,7 +68,7 @@
"dependencies": {
"chalk": "^4.1.0",
"cli-truncate": "^2.1.0",
"commander": "^6.2.1",
"commander": "^7.2.0",
"dotf": "^1.5.3",
"find-up": "^5.0.0",
"fs-extra": "^9.1.0",
Expand Down Expand Up @@ -109,6 +109,7 @@
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"tmp": "^0.2.1",
"ts-node": "^9.1.1",
"type-fest": "^0.21.2"
}
}
4 changes: 2 additions & 2 deletions src/commands/default.ts
Expand Up @@ -8,6 +8,6 @@ import type {ReadonlyDeep} from 'type-fest';
* Displays a default message when an unknown command is typed.
* @param command {string} The command that was typed.
*/
export default async (_: ReadonlyDeep<Command>, command: string): Promise<void> => {
throw new ClaspError(ERROR.COMMAND_DNE(command));
export default async (_: object, command: ReadonlyDeep<Command>): Promise<void> => {
throw new ClaspError(ERROR.COMMAND_DNE(command.args.join(' ')));
};
1 change: 0 additions & 1 deletion test/commands/list.ts
Expand Up @@ -19,7 +19,6 @@ describe('Test clasp list function', () => {
const result = spawnSync(CLASP, ['list', '--noShorten'], {encoding: 'utf8'});
expect(result.stdout).to.contain('https://script.google.com/d/');
expect(result.stdout).to.not.contain('…');
expect(result.stderr).to.equal('');
expect(result.status).to.equal(0);
});
after(cleanup);
Expand Down
8 changes: 3 additions & 5 deletions test/commands/logout.ts
Expand Up @@ -10,7 +10,8 @@ import {backupSettings, cleanup, restoreSettings, setup} from '../functions';
describe('Test clasp logout function', () => {
before(setup);
beforeEach(backupSettings);
it('should remove global AND local credentails', () => {
afterEach(restoreSettings);
it('should remove global AND local credentials', () => {
fs.writeFileSync(CLASP_PATHS.rcGlobal, FAKE_CLASPRC.token);
fs.writeFileSync(CLASP_PATHS.rcLocal, FAKE_CLASPRC.local);
const result = spawnSync(CLASP, ['logout'], {encoding: 'utf8'});
Expand All @@ -30,8 +31,5 @@ describe('Test clasp logout function', () => {
expect(result.stderr).to.equal('');
expect(result.status).to.equal(0);
});
after(() => {
restoreSettings();
cleanup();
});
after(cleanup);
});
27 changes: 9 additions & 18 deletions test/functions.ts
Expand Up @@ -38,34 +38,25 @@ export const setupWithRunManifest = () => {
/** produce a pseudo random string */
export const randomString = () => Math.random().toString(36).slice(2);

function copyFileIfExists(src: string, dest: string) {
if (fs.existsSync(src)) {
fs.copyFileSync(src, dest);
}
}
/**
* backup clasp settings. Use `restoreSettings()` to restore these.
*/
export const backupSettings = () => {
if (fs.existsSync(CLASP_PATHS.rcGlobal)) {
fs.copyFileSync(CLASP_PATHS.rcGlobal, `${CLASP_PATHS.rcGlobal}~`);
}
if (fs.existsSync(CLASP_PATHS.rcLocal)) {
fs.copyFileSync(CLASP_PATHS.rcLocal, `${CLASP_PATHS.rcLocal}~`);
}
if (fs.existsSync(CLASP_PATHS.settingsLocal)) {
fs.copyFileSync(CLASP_PATHS.settingsLocal, `${CLASP_PATHS.settingsLocal}~`);
}
const files = [CLASP_PATHS.rcGlobal, CLASP_PATHS.rcLocal, CLASP_PATHS.settingsLocal];
files.forEach(path => copyFileIfExists(path, `${path}~`));
};

/**
* restore clasp settings backuped up using `backupSettings()`
*/
export const restoreSettings = () => {
if (fs.existsSync(`${CLASP_PATHS.rcGlobal}~`)) {
fs.renameSync(`${CLASP_PATHS.rcGlobal}~`, CLASP_PATHS.rcGlobal);
}
if (fs.existsSync(`${CLASP_PATHS.rcLocal}~`)) {
fs.renameSync(`${CLASP_PATHS.rcLocal}~`, CLASP_PATHS.rcLocal);
}
if (fs.existsSync(`${CLASP_PATHS.settingsLocal}~`)) {
fs.renameSync(`${CLASP_PATHS.settingsLocal}~`, CLASP_PATHS.settingsLocal);
}
const files = [CLASP_PATHS.rcGlobal, CLASP_PATHS.rcLocal, CLASP_PATHS.settingsLocal];
files.forEach(path => copyFileIfExists(`${path}~`, path));
};

/**
Expand Down

0 comments on commit d526a9f

Please sign in to comment.