Skip to content

Commit

Permalink
Changed coverage to use c8 instead of nyc solving pnp#1271
Browse files Browse the repository at this point in the history
  • Loading branch information
waldekmastykarz committed Jan 4, 2020
1 parent 65b2c66 commit 9b95351
Show file tree
Hide file tree
Showing 93 changed files with 1,402 additions and 1,707 deletions.
4 changes: 4 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"exclude": ["**/*.spec.js", "**/clientsidepages.js"],
"reporter": ["lcov", "text", "text-summary"]
}
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defaults: &defaults
working_directory: ~/office365-cli
docker:
- image: circleci/node:10.15.3
- image: circleci/node:12.14.0

version: 2
jobs:
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
command: npm test
- run:
name: Run coveralls
command: './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
command: './node_modules/.bin/c8 report --reporter=text-lcov | ./node_modules/.bin/coveralls'
environment:
- COVERALLS_REPO_TOKEN: "VsEM7x54Sb8kg1sjzpA6aafoyvlcTtM30"
- COVERALLS_SERVICE_NAME: "circle-ci"
Expand Down
1,984 changes: 522 additions & 1,462 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "tsc -p . && node scripts/copy-files.js",
"watch": "tsc -w -p .",
"clean": "rimraf ./dist",
"test": "nyc -r=lcov -r=text mocha \"dist/**/*.spec.js\""
"test": "c8 mocha \"dist/**/*.spec.js\""
},
"keywords": [
"office 365",
Expand Down Expand Up @@ -108,6 +108,7 @@
"dependencies": {
"adal-node": "^0.2.1",
"applicationinsights": "^1.5.0",
"c8": "^7.0.0",
"easy-table": "^1.1.1",
"node-forge": "^0.9.1",
"omelette": "^0.4.12",
Expand All @@ -133,14 +134,7 @@
"@types/xmldom": "^0.1.29",
"coveralls": "^3.0.7",
"mocha": "^6.2.1",
"nyc": "^13.3.0",
"rimraf": "^3.0.0",
"sinon": "^7.5.0"
},
"nyc": {
"exclude": [
"**/*.spec.js",
"**/clientsidepages.js"
]
}
}
3 changes: 1 addition & 2 deletions src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export class Auth {
}

public ensureAccessToken(resource: string, stdout: Logger, debug: boolean = false, fetchNew: boolean = false): Promise<string> {
/* istanbul ignore next */
Logging.setLoggingOptions({
level: debug ? 3 : 0,
log: (level: LoggingLevel, message: string, error?: Error): void => {
Expand Down Expand Up @@ -347,7 +346,7 @@ export class Auth {

public cancel(): void {
if (this.userCodeInfo) {
this.authCtx.cancelRequestToGetTokenWithDeviceCode(this.userCodeInfo as UserCodeInfo, /* istanbul ignore next */(error: Error, response: TokenResponse | ErrorResponse): void => { });
this.authCtx.cancelRequestToGetTokenWithDeviceCode(this.userCodeInfo as UserCodeInfo, (error: Error, response: TokenResponse | ErrorResponse): void => { });
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ export default abstract class Command {
const cmd = commandData.match;
// required for tests not to fail.
// Can't happen on runtime because we are already inside a command
/* istanbul ignore next */
if (!cmd) {
return args;
}
Expand Down
21 changes: 13 additions & 8 deletions src/Utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,37 +292,37 @@ describe('Utils', () => {
});

it('should get server relative path when https://contoso.sharepoint.com/sites/team1', () => {
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com/sites/team1');
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com/sites/team1', '');
assert.equal(actual, '/sites/team1');
});

it('should get server relative path when https://contoso.sharepoint.com/sites/team1/', () => {
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com/sites/team1/');
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com/sites/team1/', '');
assert.equal(actual, '/sites/team1');
});

it('should get server relative path when https://contoso.sharepoint.com/', () => {
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com/');
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com/', '');
assert.equal(actual, '/');
});

it('should get server relative path when domain only', () => {
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com');
const actual = Utils.getServerRelativePath('https://contoso.sharepoint.com', '');
assert.equal(actual, '/');
});

it('should get server relative path when /sites/team1 relative path passed as param', () => {
const actual = Utils.getServerRelativePath('/sites/team1');
const actual = Utils.getServerRelativePath('/sites/team1', '');
assert.equal(actual, '/sites/team1');
});

it('should get server relative path when /sites/team1/ relative path passed as param', () => {
const actual = Utils.getServerRelativePath('/sites/team1/');
const actual = Utils.getServerRelativePath('/sites/team1/', '');
assert.equal(actual, '/sites/team1');
});

it('should get server relative path when / relative path passed as param', () => {
const actual = Utils.getServerRelativePath('/');
const actual = Utils.getServerRelativePath('/', '');
assert.equal(actual, '/');
});

Expand Down Expand Up @@ -801,7 +801,7 @@ describe('Utils', () => {
assert.equal(actual, 'Office 365 CLI Contoso');
});

it('returns empty user name when access token is undefined available', () => {
it('returns empty user name when access token is undefined', () => {
const actual = Utils.getUserNameFromAccessToken(undefined as any);
assert.equal(actual, '');
});
Expand All @@ -811,6 +811,11 @@ describe('Utils', () => {
assert.equal(actual, '');
});

it('returns empty user name when invalid access token passed', () => {
const actual = Utils.getUserNameFromAccessToken('abc.def.ghi');
assert.equal(actual, '');
});

it('isJavascriptReservedWord returns true if value equals a JavaScript Reserved Word (eg. onload)', () => {
const result = Utils.isJavascriptReservedWord('onload');
assert.strictEqual(result, true);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default class Utils {
* // returns "/sites/team1/Shared Documents"
* Utils.getServerRelativePath("/sites/team1/", "/Shared Documents");
*/
public static getServerRelativePath(webUrl: string, folderRelativePath: string = ""): string {
public static getServerRelativePath(webUrl: string, folderRelativePath: string): string {
const tenantUrl: string = `${url.parse(webUrl).protocol}//${url.parse(webUrl).hostname}`;
let webRelativePath: string = webUrl.replace(tenantUrl, '');

Expand Down
20 changes: 20 additions & 0 deletions src/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,26 @@ describe('autocomplete', () => {
}
});

it('doesnt fail when the commands file is empty', () => {
Utils.restore(fs.existsSync);
sinon.stub(fs, 'existsSync').callsFake((path) => true);
const readFileSyncStub = sinon.stub(fs, 'readFileSync').callsFake((path, encoding) => '');
(autocomplete as any).init();
try {
assert.equal(JSON.stringify((autocomplete as any).commands), JSON.stringify({}));
}
catch (e) {
fail(e);
}
finally {
Utils.restore([
fs.existsSync,
fs.readFileSync,
readFileSyncStub
]);
}
});

it('correctly lists available services when completing first fragment and it\'s empty', () => {
const evtData = {
before: "o365",
Expand Down
39 changes: 39 additions & 0 deletions src/config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as assert from 'assert';

describe('Config', () => {
before(() => {
delete require.cache[require.resolve('./config')];
});

afterEach(() => {
delete require.cache[require.resolve('./config')];
});

it('returns process.env OFFICE365CLI_TENANT value', () => {
process.env.OFFICE365CLI_TENANT = 'tenant123';

const config = require('./config');
assert.equal(config.default.tenant, 'tenant123');
});

it('returns process.env OFFICE365CLI_AADAPPID value', () => {
process.env.OFFICE365CLI_AADAPPID = 'appId123';

const config = require('./config');
assert.equal(config.default.cliAadAppId, 'appId123');
});

it('returns default value since env OFFICE365CLI_TENANT not present', () => {
delete process.env.OFFICE365CLI_TENANT;

const config = require('./config');
assert.equal(config.default.tenant, 'common');
});

it('returns default value since env OFFICE365CLI_AADAPPID not present', () => {
delete process.env.OFFICE365CLI_AADAPPID;

const config = require('./config');
assert.equal(config.default.cliAadAppId, '31359c7f-bd7e-475c-86db-fdb8c937548e');
});
});
1 change: 0 additions & 1 deletion src/o365/base/AzmgmtItemsListCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as url from 'url';
export abstract class AzmgmtItemsListCommand<T> extends AzmgmtCommand {
protected items: T[];

/* istanbul ignore next */
constructor() {
super();
this.items = [];
Expand Down
1 change: 0 additions & 1 deletion src/o365/base/GraphItemsListCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { GraphResponse } from './GraphResponse';
export abstract class GraphItemsListCommand<T> extends GraphCommand {
protected items: T[];

/* istanbul ignore next */
constructor() {
super();
this.items = [];
Expand Down
37 changes: 25 additions & 12 deletions src/o365/graph/commands/schemaextension/schemaextension-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,42 @@ class GraphSchemaExtensionAdd extends GraphCommand {
}

private validateProperties(propertiesString: string): boolean | string {
let result: boolean | string = false;

try {
const properties: any = JSON.parse(propertiesString);

// If the properties object is not an array
if (properties.length === undefined) {
return 'The specified JSON string is not an array';
}

result = 'The specified JSON string is not an array';

for (let i: number = 0; i < properties.length; i++) {
const property: any = properties[i];
if (!property.name) {
return `Property ${JSON.stringify(property)} misses name`;
}
if (!this.isValidPropertyType(property.type)) {
return `${property.type} is not a valid property type. Valid types are: Binary, Boolean, DateTime, Integer and String`;
} else {

for (let i: number = 0; i < properties.length; i++) {
const property: any = properties[i];
if (!property.name) {

result = `Property ${JSON.stringify(property)} misses name`;

}
if (!this.isValidPropertyType(property.type)) {

result = `${property.type} is not a valid property type. Valid types are: Binary, Boolean, DateTime, Integer and String`;

}
}
}

return true;
if(typeof result !== "string") {
result = true;
};
}
}
catch (e) {
return e;
result = e;
}

return result;
}

private isValidPropertyType(propertyType: string): boolean {
Expand Down
Loading

0 comments on commit 9b95351

Please sign in to comment.