Skip to content

Commit

Permalink
📦 Chore: add coverage collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Spades-S committed Mar 27, 2020
1 parent 82a4682 commit e8b30b7
Show file tree
Hide file tree
Showing 10 changed files with 597 additions and 726 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- name: npm install, make test-coverage
run: |
npm install
npm run compile
npm run test
- name: Coveralls
Expand Down
15 changes: 15 additions & 0 deletions coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"enabled": true,
"sourceRoot": "./out/src",
"output": "./coverage",
"ignorePatterns": [
"**/node_modules/**"
],
"includePid": false,
"reports": [
"html",
"lcov",
"text"
],
"verbose": false
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
"@picgo/bump-version": "^1.0.3",
"@types/glob": "^7.1.1",
"@types/inquirer": "^6.5.0",
"@types/istanbul": "^0.4.30",
"@types/mocha": "^7.0.1",
"@types/node": "^12.11.7",
"@types/request-promise-native": "^1.0.17",
Expand All @@ -313,14 +314,16 @@
"@typescript-eslint/parser": "^2.18.0",
"cz-conventional-changelog": "^3.1.0",
"cz-customizable": "6.2.0",
"decache": "^4.5.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"glob": "^7.1.6",
"husky": "^4.2.3",
"istanbul": "^0.4.5",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"prettier": "1.19.1",
"prettier": "^1.19.1",
"remap-istanbul": "^0.13.0",
"typescript": "^3.7.5",
"vscode-test": "^1.3.0"
},
Expand Down
22 changes: 22 additions & 0 deletions test/runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import * as fs from 'fs';
import * as glob from 'glob';
import * as path from 'path';
import * as Mocha from 'mocha';

import {
COVERAGE_COLLECTOR_CONFIG_FILE_PATH,
DEFAULT_COVERAGE_CONFIGURATION,
ICoverageCollectorOptions,
CoverageCollector,
} from '../utils';

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
Expand All @@ -11,7 +19,20 @@ export function run(): Promise<void> {

const testsRoot = path.resolve(__dirname, '../suite');

// collect coverage

let coverageCollectorOptions: ICoverageCollectorOptions = DEFAULT_COVERAGE_CONFIGURATION;
if (fs.existsSync(COVERAGE_COLLECTOR_CONFIG_FILE_PATH)) {
coverageCollectorOptions = require(COVERAGE_COLLECTOR_CONFIG_FILE_PATH);
}

const coverageCollector = new CoverageCollector(
path.dirname(COVERAGE_COLLECTOR_CONFIG_FILE_PATH),
coverageCollectorOptions,
);

return new Promise((resolve, reject) => {
coverageCollector.setup();
glob('**/**test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return reject(err);
Expand All @@ -24,6 +45,7 @@ export function run(): Promise<void> {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
}
coverageCollector.report();
resolve();
});
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('VSPicgo', async function() {
},
vspicgo,
});
console.log('output' + res);
console.log('output: ' + res);
assert.equal(REG4CUSTOM_OUTPUT_FORMAT.test(res), true);
});

Expand All @@ -69,7 +69,7 @@ describe('VSPicgo', async function() {
},
vspicgo,
});
console.log('uploadName' + res);
console.log('uploadName: ' + res);
assert.equal(REG4CUSTOM_FILE_FORMAT.test(res), true);
});

Expand All @@ -84,7 +84,7 @@ describe('VSPicgo', async function() {
},
vspicgo,
});
console.log('selection' + res);
console.log('selection: ' + res);
assert.equal(res.indexOf('TEST'), 2);
});
});
167 changes: 167 additions & 0 deletions test/utils/constants-and-interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import * as path from 'path';
import { Selection } from 'vscode';

import VSPicgo from '../../src/vs-picgo';

export interface IVSPicgoConfiguration {
'picgo.configPath': string | undefined;
'picgo.dataPath': string | undefined;
'picgo.customUploadName': string | undefined;
'picgo.customOutputFormat': string | undefined;
'picgo.picBed.current': string | undefined;

// aliyun picBed
'picgo.picBed.aliyun.accessKeyId': string | undefined;
'picgo.picBed.aliyun.accessKeySecret': string | undefined;
'picgo.picBed.aliyun.bucket': string | undefined;
'picgo.picBed.aliyun.area': string | undefined;
'picgo.picBed.aliyun.path': string | undefined;
'picgo.picBed.aliyun.customUrl': string | undefined;

// github picBed
'picgo.picBed.github.repo': string | undefined;
'picgo.picBed.github.token': string | undefined;
'picgo.picBed.github.path': string | undefined;
'picgo.picBed.github.customUrl': string | undefined;
'picgo.picBed.github.branch': string | undefined;

// imgur picBed
'picgo.picBed.imgur.clientId': string | undefined;
'picgo.picBed.imgur.proxy': string | undefined;

// qiniu picBed
'picgo.picBed.qiniu.accessKey': string | undefined;
'picgo.picBed.qiniu.secretKey': string | undefined;
'picgo.picBed.qiniu.bucket': string | undefined;
'picgo.picBed.qiniu.url': string | undefined;
'picgo.picBed.qiniu.area': string | undefined;
'picgo.picBed.qiniu.options': string | undefined;
'picgo.picBed.qiniu.path': string | undefined;

// sm.ms picBed
'picgo.picBed.smms.token': string | undefined;

// tcyun picBed
'picgo.picBed.tcyun.version': string | undefined;
'picgo.picBed.tcyun.secretId': string | undefined;
'picgo.picBed.tcyun.secretKey': string | undefined;
'picgo.picBed.tcyun.bucket': string | undefined;
'picgo.picBed.tcyun.appId': string | undefined;
'picgo.picBed.tcyun.area': string | undefined;
'picgo.picBed.tcyun.path': string | undefined;
'picgo.picBed.tcyun.customUrl': string | undefined;

// upyun picBed
'picgo.picBed.upyun.bucket': string | undefined;
'picgo.picBed.upyun.operator': string | undefined;
'picgo.picBed.upyun.password': string | undefined;
'picgo.picBed.upyun.options': string | undefined;
'picgo.picBed.upyun.path': string | undefined;
'picgo.picBed.upyun.url': string | undefined;

// weibo picBed
'picgo.picBed.weibo.chooseCookie': boolean | undefined;
'picgo.picBed.weibo.username': string | undefined;
'picgo.picBed.weibo.quality': string | undefined;
'picgo.picBed.weibo.cookie': string | undefined;
}

export type IVSPicgoConfigurationKeys = keyof IVSPicgoConfiguration;

export interface IVSPicgoUploadStarterOptions {
vspicgo: VSPicgo;
args4uploader: string[]; // arguments sent to func,
configuration: Partial<IVSPicgoConfiguration>;
editor: {
content: string;
selection: Selection;
};
}

export interface ICoverageCollectorOptions {
enabled: boolean;
ignorePatterns: string[];
sourceRoot: string;
includePid: boolean;
output: string;
reports: string[];
verbose: boolean;
}

export const TEST_MD_FILE_PATH = path.join(__dirname, '../../../assets/test.md');
export const TEST_PICTURE_PATH = path.join(__dirname, '../../../assets/test.png');

export const COVERAGE_COLLECTOR_CONFIG_FILE_PATH = path.join(__dirname, '../../../coverage.json');
export const DEFAULT_CONFIGS: IVSPicgoConfiguration = {
'picgo.configPath': '',
'picgo.dataPath': '',
'picgo.customUploadName': '${fileName}${extName}',
'picgo.customOutputFormat': '![${uploadedName}](${url})',
'picgo.picBed.current': 'smms',
// 'picgo.picBed.current': 'github',

// aliyun picBed
'picgo.picBed.aliyun.accessKeyId': '',
'picgo.picBed.aliyun.accessKeySecret': '',
'picgo.picBed.aliyun.bucket': '',
'picgo.picBed.aliyun.area': '',
'picgo.picBed.aliyun.path': '',
'picgo.picBed.aliyun.customUrl': '',

// github picBed
'picgo.picBed.github.repo': '',
'picgo.picBed.github.token': '',
'picgo.picBed.github.path': '',
'picgo.picBed.github.customUrl': '',
'picgo.picBed.github.branch': '',

// imgur picBed
'picgo.picBed.imgur.clientId': '',
'picgo.picBed.imgur.proxy': '',

// qiniu picBed
'picgo.picBed.qiniu.accessKey': '',
'picgo.picBed.qiniu.secretKey': '',
'picgo.picBed.qiniu.bucket': '',
'picgo.picBed.qiniu.url': '',
'picgo.picBed.qiniu.area': 'z0',
'picgo.picBed.qiniu.options': '',
'picgo.picBed.qiniu.path': '',

// sm.ms picBed
'picgo.picBed.smms.token': 'JxUI4p3alQ8QviKAd4wmQByitBufRqJS', // only for test

// tcyun picBed
'picgo.picBed.tcyun.version': 'v5',
'picgo.picBed.tcyun.secretId': '',
'picgo.picBed.tcyun.secretKey': '',
'picgo.picBed.tcyun.bucket': '',
'picgo.picBed.tcyun.appId': '',
'picgo.picBed.tcyun.area': '',
'picgo.picBed.tcyun.path': '',
'picgo.picBed.tcyun.customUrl': '',

// upyun picBed
'picgo.picBed.upyun.bucket': '',
'picgo.picBed.upyun.operator': '',
'picgo.picBed.upyun.password': '',
'picgo.picBed.upyun.options': '',
'picgo.picBed.upyun.path': '',
'picgo.picBed.upyun.url': '',

// weibo picBed
'picgo.picBed.weibo.chooseCookie': true,
'picgo.picBed.weibo.username': '',
'picgo.picBed.weibo.quality': 'large',
'picgo.picBed.weibo.cookie': '',
};

export const DEFAULT_COVERAGE_CONFIGURATION: ICoverageCollectorOptions = {
enabled: true,
sourceRoot: './out/src',
output: './coverage',
ignorePatterns: ['**/node_modules/**'],
includePid: false,
reports: ['html', 'lcov', 'text-summary'],
verbose: false,
};

0 comments on commit e8b30b7

Please sign in to comment.