From 39e06906accc0a1dc2f624a9c44c72efce56b77c Mon Sep 17 00:00:00 2001 From: Campion Fellin Date: Fri, 4 May 2018 19:45:59 -0700 Subject: [PATCH] Add more tests (#158) * Added more tests and un-skipped ones that can run without creds. Also, noted that saveProjectId should be async or return a promise Signed-off-by: campionfellin * Fix lint errors Signed-off-by: campionfellin * Fix errors in PR 158 Make saveProjectId async function Test it (without using timeout) Signed-off-by: campionfellin --- src/utils.ts | 4 ++-- tests/test.ts | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 05c4d77b..34305a07 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -218,8 +218,8 @@ export async function checkIfOnline() { * Saves the script ID in the project dotfile. * @param {string} scriptId The script ID */ -export function saveProjectId(scriptId: string): void { - DOTFILE.PROJECT().write({ scriptId }); // Save the script id +export async function saveProjectId(scriptId: string): Promise { + return DOTFILE.PROJECT().write({ scriptId }); // Save the script id } /** diff --git a/tests/test.ts b/tests/test.ts index 241627e1..97c3f54d 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -2,7 +2,9 @@ import { describe, it } from 'mocha'; import { expect } from 'chai'; import * as fs from 'fs'; const { spawnSync } = require('child_process'); -import { getScriptURL, getFileType } from './../src/utils.js'; +import { getScriptURL, getFileType, getAPIFileType, + saveProjectId } from './../src/utils.js'; +const path = require('path'); describe('Test help for each function', () => { it('should output help for run command', () => { @@ -163,14 +165,14 @@ describe.skip('Test clasp version and versions function', () => { }); }); -describe.skip('Test getScriptURL function from utils', () => { +describe('Test getScriptURL function from utils', () => { it('should return the scriptURL correctly', () => { const url = getScriptURL('abcdefghijklmnopqrstuvwxyz'); expect(url).to.equal('https://script.google.com/d/abcdefghijklmnopqrstuvwxyz/edit'); }); }); -describe.skip('Test getFileType function from utils', () => { +describe('Test getFileType function from utils', () => { it('should return the lowercase file type correctly', () => { expect(getFileType('SERVER_JS')).to.equal('js'); expect(getFileType('GS')).to.equal('gs'); @@ -178,6 +180,28 @@ describe.skip('Test getFileType function from utils', () => { }); }); +describe('Test getAPIFileType function from utils', () => { + it('should return the uppercase file type correctly', () => { + expect(getAPIFileType('file.GS')).to.equal('SERVER_JS'); + expect(getAPIFileType('file.JS')).to.equal('SERVER_JS'); + expect(getAPIFileType('file.js')).to.equal('SERVER_JS'); + expect(getAPIFileType('file.jsx')).to.equal('JSX'); + expect(getAPIFileType('file.js.html')).to.equal('HTML'); + }); +}); + +describe('Test saveProjectId function from utils', () => { + it('should save the scriptId correctly', () => { + spawnSync('rm', ['.clasp.json']); + const isSaved = async () => { + await saveProjectId('12345'); + const id = fs.readFileSync(path.join(__dirname, '/../.clasp.json'), 'utf8'); + expect(id).to.equal('{"scriptId":"12345"}'); + }; + expect(isSaved).to.not.equal(null); + }); +}); + // Fails when you logged in using --ownkey flag describe.skip('Test clasp logout function', () => { it('should logout correctly', () => { @@ -216,6 +240,10 @@ describe.skip('Test clasp logout function', () => { * [ ] clasp redeploy * [ ] clasp version [description] * [x] clasp versions + * [x] saveProjectId + * [x] getScriptURL + * [x] getFileType + * [x] getAPIFileType * * # Configs * - .js and .gs files