1 | import * as assert from 'assert';
|
2 |
|
3 | import * as JSON5 from 'json5';
|
4 |
|
5 | import { shell } from './test_functions';
|
6 | import { readFileSync } from 'fs';
|
7 |
|
8 | export function assertNodePackageVersion(version: string): void {
|
9 | assert.strictEqual(getNodePackageVersion(), version);
|
10 | }
|
11 |
|
12 | export function assertDotnetPackageVersion(filename: string, version: string): void {
|
13 | assert.strictEqual(getDotnetPackageVersion(filename), version);
|
14 | }
|
15 |
|
16 | export function assertTagCount(count: number): void {
|
17 | const tags = getGitTags();
|
18 |
|
19 | assert.strictEqual(tags.length, count);
|
20 | }
|
21 |
|
22 | export function assertTagExists(tag: string): void {
|
23 | const tags = getGitTags();
|
24 |
|
25 | assert.ok(tags.includes(tag), `Expected tag '${tag}' to exist, got: ${JSON.stringify(tags)}`);
|
26 | }
|
27 |
|
28 | export function assertTagDoesNotExist(tag: string): void {
|
29 | const tags = getGitTags();
|
30 |
|
31 | assert.ok(!tags.includes(tag), `Expected tag '${tag}' to NOT exist, got: ${JSON.stringify(tags)}`);
|
32 | }
|
33 |
|
34 | export function assertNoNewTagsCreated(callback: () => void): void {
|
35 | const tagCountBefore = getGitTags().length;
|
36 | callback.apply(null);
|
37 | assertTagCount(tagCountBefore);
|
38 | }
|
39 |
|
40 | export function assertNewTagCreated(tag: string, callback: () => void): void {
|
41 | const tagCountBefore = getGitTags().length;
|
42 | assertTagDoesNotExist(tag);
|
43 |
|
44 | callback.apply(null);
|
45 |
|
46 | assertTagExists(tag);
|
47 | assertTagCount(tagCountBefore + 1);
|
48 | }
|
49 |
|
50 | function getNodePackageVersion(): string {
|
51 | const output = shell('npm version');
|
52 | return JSON5.parse(output)['@process-engine/ci_tools'];
|
53 | }
|
54 |
|
55 | function getDotnetPackageVersion(csprojFilename: string): string {
|
56 | const contents = readFileSync(csprojFilename, { encoding: 'utf-8' });
|
57 | const matches = contents.match(/(<Version>)([^<]+)</);
|
58 |
|
59 | return matches == null ? null : matches[2];
|
60 | }
|
61 |
|
62 | function getGitTags(): string[] {
|
63 | return shell('git tag --sort=-creatordate')
|
64 | .trim()
|
65 | .split('\n');
|
66 | }
|