Skip to content

Commit

Permalink
fix(tests): Enable parallel testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jroehl committed May 7, 2020
1 parent 7bade56 commit af4a91e
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 122 deletions.
10 changes: 10 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require": ["ts-node/register", "source-map-support/register"],
"extension": ["ts"],
"recursive": true,
"delay": false,
"timeout": 15000,
"reporter": "spec",
"forbid-only": true,
"file": "test/commands/hooks.test.ts"
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.20.1
6 changes: 6 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extension": [".ts"],
"include": ["test/**/*.ts"],
"exclude": ["**/*.d.ts"],
"all": true
}
4 changes: 1 addition & 3 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

require('@oclif/command').run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'))
require('@oclif/command').run().then(require('@oclif/command/flush')).catch(require('@oclif/errors/handle'));
4 changes: 2 additions & 2 deletions docs/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ OPTIONS
-r, --rawOutput Get the raw output as a JSON string
-s, --spreadsheetId=spreadsheetId (required) ID of the spreadsheet to use
-t, --worksheetTitle=worksheetTitle (required) Title of the worksheet to use
-v, --valueInputOption=valueInputOption [default: RAW] The style of the input ("RAW" or "USER_ENTERED")
-v, --valueInputOption=RAW|USER_ENTERED [default: RAW] The style of the input ("RAW" or "USER_ENTERED")
--minCol=minCol [default: 1] The optional starting col of the operation
EXAMPLE
Expand Down Expand Up @@ -89,7 +89,7 @@ OPTIONS
-r, --rawOutput Get the raw output as a JSON string
-s, --spreadsheetId=spreadsheetId (required) ID of the spreadsheet to use
-t, --worksheetTitle=worksheetTitle (required) Title of the worksheet to use
-v, --valueInputOption=valueInputOption [default: RAW] The style of the input ("RAW" or "USER_ENTERED")
-v, --valueInputOption=RAW|USER_ENTERED [default: RAW] The style of the input ("RAW" or "USER_ENTERED")
--minCol=minCol [default: 1] The optional starting col of the operation
--minRow=minRow [default: 1] The optional starting row of the operation
Expand Down
2 changes: 1 addition & 1 deletion docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ OPTIONS
--all see all commands in CLI
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.0.0/src/commands/help.ts)_
51 changes: 9 additions & 42 deletions package-lock.json

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

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
},
"bugs": "https://github.com/jroehl/google-sheet-cli/issues",
"dependencies": {
"@oclif/command": "^1.5.20",
"@oclif/command": "^1.6.1",
"@oclif/config": "^1.15.1",
"@oclif/plugin-help": "^3.0.0",
"cli-ux": "^5.4.5",
"googleapis": "^49.0.0",
"husky": "^4.2.5",
"lodash.get": "^4.4.2",
"semantic-release": "^17.0.6",
"tslib": "^1.11.1"
"tslib": "^1.11.2"
},
"devDependencies": {
"@oclif/dev-cli": "^1.22.2",
"@oclif/test": "^1.2.5",
"@types/chai": "^4.2.11",
"@types/lodash.get": "^4.4.6",
"@types/mocha": "^7.0.2",
"@types/node": "^13.13.1",
"@types/node": "^13.13.5",
"chai": "^4.2.0",
"globby": "^11.0.0",
"mocha": "^7.1.1",
"mocha": "^7.1.2",
"nyc": "^15.0.1",
"ts-node": "^8.9.0",
"source-map-support": "^0.5.19",
"ts-node": "^8.10.1",
"typescript": "^3.8.3"
},
"engines": {
Expand Down Expand Up @@ -77,7 +78,7 @@
"postpack": "rm -f oclif.manifest.json",
"version": "oclif-dev readme --multi && sh ./bin/clean.sh && git add README.md docs/*.md",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme --multi",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"test": "nyc mocha \"test/**/*.test.ts\"",
"semantic-release": "semantic-release"
},
"types": "lib/index.d.ts"
Expand Down
14 changes: 6 additions & 8 deletions src/lib/base-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ export const spreadsheetId = flags.string({
char: 's',
description: 'ID of the spreadsheet to use',
required: true,
env: 'SPREADSHEET_ID',
});

export const worksheetTitle = flags.string({
char: 't',
description: 'Title of the worksheet to use',
required: true,
env: 'WORKSHEET_TITLE',
});

export const valueInputOption = flags.string({
char: 'v',
description: 'The style of the input ("RAW" or "USER_ENTERED")',
required: false,
options: [GoogleSheetCli.ValueInputOption.RAW, GoogleSheetCli.ValueInputOption.USER_ENTERED],
default: GoogleSheetCli.ValueInputOption.RAW,
env: 'VALUE_INPUT_OPTION',
});

export const data = {
name: 'data',
type: 'string',
description: 'The data to be used as a JSON string - nested array [["1", "2", "3"]]',
required: true,
env: 'DATA',
};

export default abstract class extends Command {
Expand Down Expand Up @@ -82,13 +86,7 @@ export default abstract class extends Command {
}

async catch(err: Error) {
this.stop('errored');
this.error(err.message || err);
process.exit(1);
this.error(err, { exit: 1 });
// handle any error from the command
}

async finally(err: Error) {
// called after run and catch regardless of whether or not the command errored
}
}
2 changes: 1 addition & 1 deletion src/lib/google-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default class GoogleSheet {
requests: [
{
deleteSheet: {
sheetId: sheet.properties && sheet.properties.sheetId ? sheet.properties.sheetId : -1,
sheetId: sheet.properties?.sheetId || -1,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const parseRanges = (options: GoogleSheetCli.QueryOptions = {}): GoogleSh
return a1Notations
.replace(/[,;]/g, ',')
.split(',')
.map(a1Notation => {
.map((a1Notation) => {
const [from, to] = a1Notation.split(':');
const { col: minCol, row: minRow } = parseA1Notation(from);
const { col: maxCol, row: maxRow } = parseA1Notation(to);
Expand Down
17 changes: 13 additions & 4 deletions test/commands/data/append.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { expect } from '@oclif/test';
import { testRun, WORKSHEET_TITLE_DELETE as worksheetTitle } from '../helper';
import { testRun, DATA_APPEND as worksheetTitle } from '../helper';

const baseCommand = 'data:append';

const DATA = [
['1', '2'],
['foo', ''],
];
const DATA_STRING = JSON.stringify(DATA);

describe(baseCommand, () => {
testRun([baseCommand, '[["1", "2"], ["foo"]]'], worksheetTitle, (stdout: string) => {
testRun([baseCommand, DATA_STRING], worksheetTitle, (stdout: string) => {
expect(stdout).to.contain(`Data successfully appended to "${worksheetTitle}"`);
});
testRun([baseCommand, '[["1", "2"], ["foo"]]', '--rawOutput'], worksheetTitle, (parsed: {}) => {
testRun([baseCommand, DATA_STRING, '--rawOutput'], worksheetTitle, (parsed: {}) => {
expect(parsed).to.eql({
operation: 'data:append',
worksheetTitle,
data: [['1', '2'], ['foo']],
data: DATA,
});
});
testRun(['data:get', '--rawOutput'], worksheetTitle, (parsed: {}) => {
expect((parsed as any).rawData).to.eql([...DATA, ...DATA]);
});
});
23 changes: 15 additions & 8 deletions test/commands/data/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@oclif/test';
import { testRun, WORKSHEET_TITLE_CHANGE as worksheetTitle } from '../helper';
import { testRun, DATA_GET as worksheetTitle, RAW_DATA } from '../helper';

const baseCommand = 'data:get';

Expand All @@ -16,7 +16,7 @@ describe(baseCommand, () => {
testRun([baseCommand, '--rawOutput'], worksheetTitle, (parsed: {}) => {
expect(parsed).to.eql({
operation: 'data:get',
rawData: [['A1', 'B1', 'C1'], ['', 'B2', 'C2'], ['A3', '', 'C3'], ['A4', 'B4', ''], ['A5', '', 'C5'], ['', 'B6', 'C6'], ['A7', 'B7', 'C7']],
rawData: RAW_DATA,
formatted: [
{
'(A)': 'A1',
Expand Down Expand Up @@ -55,14 +55,21 @@ describe(baseCommand, () => {
},
],
header: ['(A)', '(B)', '(C)'],
range: `'${worksheetTitle}'!A1:Z1000`,
range: `${worksheetTitle}!A1:Z1000`,
});
});

testRun([baseCommand, '--rawOutput', '--hasHeaderRow'], worksheetTitle, (parsed: {}) => {
expect(parsed).to.eql({
operation: 'data:get',
rawData: [['', 'B2', 'C2'], ['A3', '', 'C3'], ['A4', 'B4', ''], ['A5', '', 'C5'], ['', 'B6', 'C6'], ['A7', 'B7', 'C7']],
rawData: [
['', 'B2', 'C2'],
['A3', '', 'C3'],
['A4', 'B4', ''],
['A5', '', 'C5'],
['', 'B6', 'C6'],
['A7', 'B7', 'C7'],
],
formatted: [
{
A1: '',
Expand Down Expand Up @@ -96,7 +103,7 @@ describe(baseCommand, () => {
},
],
header: ['A1', 'B1', 'C1'],
range: `'${worksheetTitle}'!A1:Z1000`,
range: `${worksheetTitle}!A1:Z1000`,
});
});

Expand All @@ -110,7 +117,7 @@ describe(baseCommand, () => {
},
],
header: ['B1'],
range: `'${worksheetTitle}'!B2`,
range: `${worksheetTitle}!B2`,
});
});

Expand All @@ -124,7 +131,7 @@ describe(baseCommand, () => {
},
],
header: ['C1'],
range: `'${worksheetTitle}'!C3`,
range: `${worksheetTitle}!C3`,
});
});

Expand All @@ -134,7 +141,7 @@ describe(baseCommand, () => {
rawData: [],
formatted: [],
header: ['A1'],
range: `'${worksheetTitle}'!A2`,
range: `${worksheetTitle}!A2`,
});
});
});
11 changes: 7 additions & 4 deletions test/commands/data/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { expect } from '@oclif/test';
import { testRun, WORKSHEET_TITLE_DELETE as worksheetTitle } from '../helper';
import { testRun, DATA_UPDATE as worksheetTitle } from '../helper';

const baseCommand = 'data:update';

const DATA = [['1', '2'], ['foo']];
const DATA_STRING = JSON.stringify(DATA);

describe(baseCommand, () => {
testRun([baseCommand, '[["1", "2"], ["foo"]]'], worksheetTitle, async (stdout: string) => {
testRun([baseCommand, DATA_STRING], worksheetTitle, async (stdout: string) => {
expect(stdout).to.contain(`Data successfully updated in "${worksheetTitle}"`);
});
testRun([baseCommand, '[["1", "2"], ["foo"]]', '--rawOutput'], worksheetTitle, async (parsed: {}) => {
testRun([baseCommand, DATA_STRING, '--rawOutput'], worksheetTitle, async (parsed: {}) => {
expect(parsed).to.eql({
operation: 'data:update',
worksheetTitle,
data: [['1', '2'], ['foo']],
data: DATA,
});
});
});

0 comments on commit af4a91e

Please sign in to comment.