Skip to content

Commit

Permalink
Modify tests to avoid spawnSync behavior on Windows (#232)
Browse files Browse the repository at this point in the history
Fixes #231

- [X] `npm run test` succeeds. (!)
- [X] `npm run lint` succeeds.
- [X] Appropriate changes to README are included in PR. (N/A)
  • Loading branch information
wilt00 authored and grant committed Jun 25, 2018
1 parent ee8889f commit 304978f
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import { getAPIFileType, getScriptURL, saveProjectId } from './../src/utils.js';
const { spawnSync } = require('child_process');
const TEST_CODE_JS = 'function test() { Logger.log(\'test\'); }';
const TEST_JSON = '{"timeZone": "America/New_York"}';
const CLASP = (os.type() === 'Windows_NT') ? 'clasp.cmd' : 'clasp';

describe('Test help for each function', () => {
it('should output help for run command', () => {
const result = spawnSync(
'clasp', ['run', '--help'], { encoding : 'utf8' },
CLASP, ['run', '--help'], { encoding : 'utf8' },
);
expect(result.status).to.equal(0);
expect(result.stdout).to.include('Run a function in your Apps Scripts project');
});
it('should output help for logs command', () => {
const result = spawnSync(
'clasp', ['logs', '--help'], { encoding : 'utf8' },
CLASP, ['logs', '--help'], { encoding : 'utf8' },
);
expect(result.status).to.equal(0);
expect(result.stdout).to.include('Shows the StackDriver logs');
Expand All @@ -30,7 +31,7 @@ describe('Test help for each function', () => {
describe.skip('Test clasp list function', () => {
it('should list clasp projects correctly', () => {
const result = spawnSync(
'clasp', ['list'], { encoding: 'utf8' },
CLASP, ['list'], { encoding: 'utf8' },
);
// Every project starts with this base URL, thus
// using clasp list should at least contain this
Expand All @@ -44,15 +45,15 @@ describe.skip('Test clasp create function', () => {
it('should prompt for a project name correctly', () => {
spawnSync('rm', ['.clasp.json']);
const result = spawnSync(
'clasp', ['create'], { encoding: 'utf8' },
CLASP, ['create'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Give a script title:');
expect(result.status).to.equal(0);
});
it('should not prompt for project name', () => {
fs.writeFileSync('.clasp.json', '');
const result = spawnSync(
'clasp', ['create'], { encoding: 'utf8' },
CLASP, ['create'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('Project file (.clasp.json) already exists.');
});
Expand All @@ -62,7 +63,7 @@ describe.skip('Test clasp create <title> function', () => {
it('should create a new project named <title> correctly', () => {
spawnSync('rm', ['.clasp.json']);
const result = spawnSync(
'clasp', ['create', 'myTitle'], { encoding: 'utf8' },
CLASP, ['create', 'myTitle'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Created new script: https://script.google.com/d/');
expect(result.status).to.equal(0);
Expand All @@ -74,15 +75,15 @@ describe.skip('Test clasp clone <scriptId> function', () => {
const settings = JSON.parse(fs.readFileSync('.clasp.json', 'utf8'));
fs.removeSync('.clasp.json');
const result = spawnSync(
'clasp', ['clone', settings.scriptId], { encoding: 'utf8' },
CLASP, ['clone', settings.scriptId], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Cloned');
expect(result.stdout).to.contain('files.');
expect(result.status).to.equal(0);
});
it('should give an error on a non-existing project', () => {
const result = spawnSync(
'clasp', ['clone', 'non-existing-project'], { encoding: 'utf8' },
CLASP, ['clone', 'non-existing-project'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('> Did you provide the correct scriptId?');
expect(result.status).to.equal(1);
Expand All @@ -92,7 +93,7 @@ describe.skip('Test clasp clone <scriptId> function', () => {
describe.skip('Test clasp pull function', () => {
it('should pull an existing project correctly', () => {
const result = spawnSync(
'clasp', ['pull'], { encoding: 'utf8' },
CLASP, ['pull'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Cloned');
expect(result.stdout).to.contain('files.');
Expand All @@ -107,7 +108,7 @@ describe.skip('Test clasp push function', () => {
fs.writeFileSync('appsscript.json', TEST_JSON);
fs.writeFileSync('.claspignore', '**/**\n!Code.js\n!appsscript.json');
const result = spawnSync(
'clasp', ['push'], { encoding: 'utf8' },
CLASP, ['push'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Pushed');
expect(result.stdout).to.contain('files.');
Expand All @@ -117,7 +118,7 @@ describe.skip('Test clasp push function', () => {
fs.writeFileSync('.claspignore', '**/**\n!Code.js\n!appsscript.json\n!unexpected_file');
fs.writeFileSync('unexpected_file', TEST_CODE_JS);
const result = spawnSync(
'clasp', ['push'], { encoding: 'utf8' },
CLASP, ['push'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('Invalid value at');
expect(result.stderr).to.contain('UNEXPECTED_FILE');
Expand All @@ -143,8 +144,8 @@ describe.skip('Test clasp status function', () => {
{ file: 'shouldBeIgnored', data: TEST_CODE_JS },
{ file: 'should/alsoBeIgnored', data: TEST_CODE_JS },
]);
spawnSync('clasp', ['create', '[TEST] clasp status'], { encoding: 'utf8', cwd: tmpdir });
const result = spawnSync('clasp', ['status', '--json'], { encoding: 'utf8', cwd: tmpdir });
spawnSync(CLASP, ['create', '[TEST] clasp status'], { encoding: 'utf8', cwd: tmpdir });
const result = spawnSync(CLASP, ['status', '--json'], { encoding: 'utf8', cwd: tmpdir });
expect(result.status).to.equal(0);
const resultJson = JSON.parse(result.stdout);
expect(resultJson.untrackedFiles).to.have.members(['shouldBeIgnored', 'should/alsoBeIgnored']);
Expand All @@ -157,8 +158,8 @@ describe.skip('Test clasp status function', () => {
{ file: 'appsscript.json', data: TEST_JSON },
{ file: 'node_modules/fsevents/build/Release/.deps/Release/.node.d', data: TEST_CODE_JS },
]);
spawnSync('clasp', ['create', '[TEST] clasp status'], { encoding: 'utf8', cwd: tmpdir });
const result = spawnSync('clasp', ['status', '--json'], { encoding: 'utf8', cwd: tmpdir });
spawnSync(CLASP, ['create', '[TEST] clasp status'], { encoding: 'utf8', cwd: tmpdir });
const result = spawnSync(CLASP, ['status', '--json'], { encoding: 'utf8', cwd: tmpdir });
expect(result.status).to.equal(0);
const resultJson = JSON.parse(result.stdout);
expect(resultJson.untrackedFiles).to.have.members([
Expand All @@ -170,7 +171,7 @@ describe.skip('Test clasp status function', () => {
describe.skip('Test clasp open function', () => {
it('should open a project correctly', () => {
const result = spawnSync(
'clasp', ['open'], { encoding: 'utf8' },
CLASP, ['open'], { encoding: 'utf8' },
);
//should open a browser with the project
expect(result.status).to.equal(0);
Expand All @@ -180,7 +181,7 @@ describe.skip('Test clasp open function', () => {
describe.skip('Test clasp deployments function', () => {
it('should list deployments correctly', () => {
const result = spawnSync(
'clasp', ['deployments'], { encoding: 'utf8' },
CLASP, ['deployments'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Deployment');
expect(result.status).to.equal(0);
Expand All @@ -190,7 +191,7 @@ describe.skip('Test clasp deployments function', () => {
describe.skip('Test clasp deploy function', () => {
it('should deploy correctly', () => {
const result = spawnSync(
'clasp', ['deploy'], { encoding: 'utf8' },
CLASP, ['deploy'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Created version ');
expect(result.status).to.equal(0);
Expand All @@ -201,14 +202,14 @@ describe.skip('Test clasp version and versions function', () => {
let versionNumber = '';
it('should create new version correctly', () => {
const result = spawnSync(
'clasp', ['version'], { encoding: 'utf8' },
CLASP, ['version'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Created version ');
expect(result.status).to.equal(0);
versionNumber = result.stdout.substring(result.stdout.lastIndexOf(' '), result.stdout.length - 2);
it('should list versions correctly', () => {
const result = spawnSync(
'clasp', ['versions'], { encoding: 'utf8' },
CLASP, ['versions'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Versions');
expect(result.stdout).to.contain(versionNumber + ' - ');
Expand All @@ -221,15 +222,15 @@ describe.skip('Test clasp clone function', () => {
it('should prompt for which script to clone correctly', () => {
spawnSync('rm', ['.clasp.json']);
const result = spawnSync(
'clasp', ['clone'], { encoding: 'utf8' },
CLASP, ['clone'], { encoding: 'utf8' },
);
expect(result.stdout).to.contain('Clone which script?');
expect(result.status).to.equal(0);
});
it('should give an error if .clasp.json already exists', () => {
fs.writeFileSync('.clasp.json', '');
const result = spawnSync(
'clasp', ['clone'], { encoding: 'utf8' },
CLASP, ['clone'], { encoding: 'utf8' },
);
expect(result.stderr).to.contain('Project file (.clasp.json) already exists.');
expect(result.status).to.equal(1);
Expand Down Expand Up @@ -278,7 +279,7 @@ describe('Test clasp logout function', () => {
fs.writeFileSync('.clasprc.json', TEST_JSON);
fs.writeFileSync(path.join(os.homedir(), '/.clasprc.json'), TEST_JSON);
const result = spawnSync(
'clasp', ['logout'], { encoding: 'utf8' },
CLASP, ['logout'], { encoding: 'utf8' },
);
expect(result.status).to.equal(0);
const localDotExists = fs.existsSync('.clasprc.json');
Expand Down

0 comments on commit 304978f

Please sign in to comment.