mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-08 14:32:50 +00:00
test: add tests for get-used-version task
This commit is contained in:
1754
package-lock.json
generated
1754
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@@ -16,6 +16,7 @@
|
||||
"prepublishOnly": "npm ci && npm run build",
|
||||
"preversion": "npm run prepublishOnly",
|
||||
"push": "git push && git push origin \"v$npm_package_version\"",
|
||||
"test": "nyc mocha --require ts-node/register --ui mocha-typescript 'test/**/*.spec.ts'",
|
||||
"tslint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'"
|
||||
},
|
||||
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
|
||||
@@ -33,14 +34,24 @@
|
||||
"@types/glob": "7.1.1",
|
||||
"@types/mustache": "0.8.32",
|
||||
"@types/node": "10.14.12",
|
||||
"@types/tmp": "0.1.0",
|
||||
"commander": "2.20.0",
|
||||
"glob": "7.1.4",
|
||||
"moment": "2.24.0",
|
||||
"mustache": "3.0.1"
|
||||
"mustache": "3.0.1",
|
||||
"tmp": "0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@openstapps/configuration": "0.21.0",
|
||||
"@types/chai": "4.1.7",
|
||||
"@types/chai-as-promised": "7.1.0",
|
||||
"@types/mocha": "5.2.7",
|
||||
"chai": "4.2.0",
|
||||
"chai-as-promised": "7.1.1",
|
||||
"conventional-changelog-cli": "2.0.21",
|
||||
"mocha": "6.1.4",
|
||||
"mocha-typescript": "1.1.17",
|
||||
"nyc": "14.1.1",
|
||||
"prepend-file-cli": "1.0.6",
|
||||
"rimraf": "2.6.3",
|
||||
"ts-node": "8.3.0",
|
||||
@@ -52,5 +63,27 @@
|
||||
"typings": "lib/common.d.ts",
|
||||
"bin": {
|
||||
"openstapps-projectmanagement": "lib/cli.js"
|
||||
},
|
||||
"nyc": {
|
||||
"all": true,
|
||||
"branches": 95,
|
||||
"check-coverage": true,
|
||||
"include": [
|
||||
"src/tasks/get-used-version.ts"
|
||||
],
|
||||
"extension": [
|
||||
".ts"
|
||||
],
|
||||
"functions": 95,
|
||||
"lines": 95,
|
||||
"per-file": true,
|
||||
"reporter": [
|
||||
"html",
|
||||
"text-summary"
|
||||
],
|
||||
"require": [
|
||||
"ts-node/register"
|
||||
],
|
||||
"statements": 95
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export async function getUsedVersion(path: PathLike, dependency: string): Promis
|
||||
export async function getUsedVersionMajorMinor(path: PathLike, dependency: string): Promise<string> {
|
||||
const versionMatch = (await getUsedVersion(path, dependency)).match(/([0-9]+\.[0-9]+)\.[0-9]+/);
|
||||
|
||||
// istanbul ignore if
|
||||
if (versionMatch === null) {
|
||||
throw new Error(`Used version of '${dependency}' of project in '${path}' could not be determined.`);
|
||||
}
|
||||
|
||||
43
test/get-used-versions.spec.ts
Normal file
43
test/get-used-versions.spec.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import * as chai from 'chai';
|
||||
import {expect} from 'chai';
|
||||
import * as chaiAsPromised from 'chai-as-promised';
|
||||
import {execSync} from 'child_process';
|
||||
import {suite, test} from 'mocha-typescript';
|
||||
import {join} from 'path';
|
||||
import {dirSync} from 'tmp';
|
||||
import {getUsedVersion, getUsedVersionMajorMinor} from '../src/tasks/get-used-version';
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
chai.should();
|
||||
|
||||
@suite()
|
||||
export class GetUsedVersionsSpec {
|
||||
@test
|
||||
async 'does not depend on core'() {
|
||||
return getUsedVersion(join(__dirname, '..'), '@openstapps/core').should.eventually.be.rejected;
|
||||
}
|
||||
|
||||
@test
|
||||
async 'not a Node.js project'() {
|
||||
return getUsedVersion(__dirname, '@openstapps/core').should.eventually.be.rejected;
|
||||
}
|
||||
|
||||
@test
|
||||
async 'has no dependencies'() {
|
||||
const temporaryDirectory = dirSync();
|
||||
|
||||
execSync(`cd ${temporaryDirectory.name}; npm init -y`);
|
||||
|
||||
await getUsedVersion(temporaryDirectory.name, '@openstapps/core').should.eventually.be.rejected;
|
||||
}
|
||||
|
||||
@test
|
||||
async 'get used version'() {
|
||||
expect(await getUsedVersion(join(__dirname, '..'), '@krlwlfrt/async-pool')).to.be.equal('0.1.0');
|
||||
}
|
||||
|
||||
@test
|
||||
async 'get used version major minor'() {
|
||||
expect(await getUsedVersionMajorMinor(join(__dirname, '..'), '@krlwlfrt/async-pool')).to.be.equal('0.1');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user