@contrail/flexplm 1.3.1-alpha.585afc1 → 1.3.1-alpha.7db7b62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli/commands/upload.d.ts +0 -9
- package/lib/cli/commands/upload.js +1 -3
- package/lib/cli/index.d.ts +1 -1
- package/lib/cli/index.js +4 -8
- package/lib/interfaces/mapping-file.d.ts +2 -2
- package/lib/util/type-conversion-utils.d.ts +1 -2
- package/lib/util/type-conversion-utils.js +1 -4
- package/package.json +1 -1
- package/lib/cli/commands/compile.spec.d.ts +0 -1
- package/lib/cli/commands/compile.spec.js +0 -80
- package/lib/cli/commands/create.spec.d.ts +0 -1
- package/lib/cli/commands/create.spec.js +0 -78
- package/lib/cli/commands/upload.spec.d.ts +0 -1
- package/lib/cli/commands/upload.spec.js +0 -88
- package/lib/cli/index.spec.d.ts +0 -1
- package/lib/cli/index.spec.js +0 -79
|
@@ -1,10 +1 @@
|
|
|
1
|
-
interface UploadOptions {
|
|
2
|
-
filePath: string;
|
|
3
|
-
message?: string;
|
|
4
|
-
branch?: string;
|
|
5
|
-
skipGit: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare function parseUploadArgs(args: string[]): UploadOptions;
|
|
8
|
-
export declare function buildCommitMessage(userMessage: string, fileId: string): string;
|
|
9
1
|
export declare function runUpload(args: string[]): Promise<void>;
|
|
10
|
-
export {};
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.runUpload =
|
|
26
|
+
exports.runUpload = void 0;
|
|
27
27
|
const child_process_1 = require("child_process");
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const path = __importStar(require("path"));
|
|
@@ -91,7 +91,6 @@ function parseUploadArgs(args) {
|
|
|
91
91
|
}
|
|
92
92
|
return { filePath, message, branch, skipGit };
|
|
93
93
|
}
|
|
94
|
-
exports.parseUploadArgs = parseUploadArgs;
|
|
95
94
|
function runGit(args, cwd) {
|
|
96
95
|
return (0, child_process_1.execFileSync)('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
97
96
|
}
|
|
@@ -113,7 +112,6 @@ function buildCommitMessage(userMessage, fileId) {
|
|
|
113
112
|
lines[0] = `${lines[0]} [fileId: ${fileId}]`;
|
|
114
113
|
return lines.join('\n');
|
|
115
114
|
}
|
|
116
|
-
exports.buildCommitMessage = buildCommitMessage;
|
|
117
115
|
async function commitToGit(absPath, fileId, options) {
|
|
118
116
|
const repoDir = path.dirname(absPath);
|
|
119
117
|
const versionCheck = tryRunGit(['--version'], repoDir);
|
package/lib/cli/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export
|
|
2
|
+
export {};
|
package/lib/cli/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.main = void 0;
|
|
5
4
|
const create_1 = require("./commands/create");
|
|
6
5
|
const compile_1 = require("./commands/compile");
|
|
7
6
|
const upload_1 = require("./commands/upload");
|
|
@@ -55,10 +54,7 @@ async function main() {
|
|
|
55
54
|
process.exit(1);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
process.exit(1);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
57
|
+
main().catch((err) => {
|
|
58
|
+
console.error(err && err.message ? err.message : err);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
});
|
|
@@ -71,7 +71,7 @@ export interface DirectionalSection {
|
|
|
71
71
|
* (flex2vibe) for a row when it cannot be derived from the row itself.
|
|
72
72
|
*
|
|
73
73
|
* Consulted by `TypeConversionUtils.getObjectTypePath` /
|
|
74
|
-
* `
|
|
74
|
+
* `getEntityTypePathFromOjbect` after the explicit `flexPLMTypePath` /
|
|
75
75
|
* `vibeIQTypePath` property and before the `TypeDefaults` fallback.
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
@@ -95,7 +95,7 @@ export interface DirectionalSection {
|
|
|
95
95
|
* custStyleNumber: 'styleNumber',
|
|
96
96
|
* }
|
|
97
97
|
*/
|
|
98
|
-
rekey?:
|
|
98
|
+
rekey?: Record<string, unknown>;
|
|
99
99
|
/**
|
|
100
100
|
* Lookup table consumed by REMOVE tasks in {@link DirectionalSection.transformOrder}.
|
|
101
101
|
*
|
|
@@ -92,7 +92,6 @@ export declare class TypeConversionUtils {
|
|
|
92
92
|
* @returns Promise<string>
|
|
93
93
|
*/
|
|
94
94
|
static getEntityClassFromObject(fileId: any, mapFileUtil: any, object: any): Promise<string>;
|
|
95
|
-
static getEntityTypePathFromOjbect(fileId: any, mapFileUtil: any, object: any): Promise<string>;
|
|
96
95
|
/** Takes in a FlexPLM object and returns the correct VibeIQ
|
|
97
96
|
* type associated to the object. Order of precedence
|
|
98
97
|
* Property 'vibeIQTypePath'
|
|
@@ -105,7 +104,7 @@ export declare class TypeConversionUtils {
|
|
|
105
104
|
* @param entity VibeIQ entity
|
|
106
105
|
* @returns Promise<string>
|
|
107
106
|
*/
|
|
108
|
-
static
|
|
107
|
+
static getEntityTypePathFromOjbect(fileId: any, mapFileUtil: any, object: any): Promise<string>;
|
|
109
108
|
/**Takes in a FlexPLM object and returns the correct
|
|
110
109
|
* identifier properties. Order of precedence
|
|
111
110
|
* Property 'vibeIQIdentifierProperties'
|
|
@@ -199,9 +199,6 @@ class TypeConversionUtils {
|
|
|
199
199
|
}
|
|
200
200
|
return type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
|
|
201
201
|
}
|
|
202
|
-
static async getEntityTypePathFromOjbect(fileId, mapFileUtil, object) {
|
|
203
|
-
return await this.getEntityTypePathFromObject(fileId, mapFileUtil, object);
|
|
204
|
-
}
|
|
205
202
|
/** Takes in a FlexPLM object and returns the correct VibeIQ
|
|
206
203
|
* type associated to the object. Order of precedence
|
|
207
204
|
* Property 'vibeIQTypePath'
|
|
@@ -214,7 +211,7 @@ class TypeConversionUtils {
|
|
|
214
211
|
* @param entity VibeIQ entity
|
|
215
212
|
* @returns Promise<string>
|
|
216
213
|
*/
|
|
217
|
-
static async
|
|
214
|
+
static async getEntityTypePathFromOjbect(fileId, mapFileUtil, object) {
|
|
218
215
|
let typePath = object['vibeIQTypePath'];
|
|
219
216
|
if (typePath) {
|
|
220
217
|
return typePath;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs = __importStar(require("fs"));
|
|
27
|
-
const os = __importStar(require("os"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const compile_1 = require("./compile");
|
|
30
|
-
describe('runCompile', () => {
|
|
31
|
-
let tempDir;
|
|
32
|
-
let originalCwd;
|
|
33
|
-
let logSpy;
|
|
34
|
-
let stderrSpy;
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
originalCwd = process.cwd();
|
|
37
|
-
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'flexplm-compile-'));
|
|
38
|
-
process.chdir(tempDir);
|
|
39
|
-
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
40
|
-
stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
41
|
-
});
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
logSpy.mockRestore();
|
|
44
|
-
stderrSpy.mockRestore();
|
|
45
|
-
process.chdir(originalCwd);
|
|
46
|
-
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
47
|
-
});
|
|
48
|
-
it('transpiles a .ts file to a sibling .js file', async () => {
|
|
49
|
-
const tsPath = path.join(tempDir, 'mapping.ts');
|
|
50
|
-
fs.writeFileSync(tsPath, `export const mapping = { orgName: 'acme' };\n`, 'utf8');
|
|
51
|
-
await (0, compile_1.runCompile)('mapping.ts');
|
|
52
|
-
const jsPath = path.join(tempDir, 'mapping.js');
|
|
53
|
-
expect(fs.existsSync(jsPath)).toBe(true);
|
|
54
|
-
const js = fs.readFileSync(jsPath, 'utf8');
|
|
55
|
-
expect(js).toContain('exports.mapping');
|
|
56
|
-
expect(js).toContain("orgName: 'acme'");
|
|
57
|
-
});
|
|
58
|
-
it('resolves the input path relative to cwd', async () => {
|
|
59
|
-
const subdir = path.join(tempDir, 'nested');
|
|
60
|
-
fs.mkdirSync(subdir);
|
|
61
|
-
const tsPath = path.join(subdir, 'm.ts');
|
|
62
|
-
fs.writeFileSync(tsPath, 'export const x = 1;\n', 'utf8');
|
|
63
|
-
await (0, compile_1.runCompile)('nested/m.ts');
|
|
64
|
-
expect(fs.existsSync(path.join(subdir, 'm.js'))).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
it('throws when the input file does not exist', async () => {
|
|
67
|
-
await expect((0, compile_1.runCompile)('nope.ts')).rejects.toThrow(/File not found/);
|
|
68
|
-
});
|
|
69
|
-
it('throws when the input is not a .ts file', async () => {
|
|
70
|
-
const jsPath = path.join(tempDir, 'mapping.js');
|
|
71
|
-
fs.writeFileSync(jsPath, 'module.exports = {};', 'utf8');
|
|
72
|
-
await expect((0, compile_1.runCompile)('mapping.js')).rejects.toThrow(/Expected a \.ts file/);
|
|
73
|
-
});
|
|
74
|
-
it('throws on a TypeScript syntax error', async () => {
|
|
75
|
-
const tsPath = path.join(tempDir, 'broken.ts');
|
|
76
|
-
fs.writeFileSync(tsPath, 'export const = ;\n', 'utf8');
|
|
77
|
-
await expect((0, compile_1.runCompile)('broken.ts')).rejects.toThrow(/Compile failed/);
|
|
78
|
-
expect(fs.existsSync(path.join(tempDir, 'broken.js'))).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs = __importStar(require("fs"));
|
|
27
|
-
const os = __importStar(require("os"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
let nextAnswer = '';
|
|
30
|
-
jest.mock('readline', () => ({
|
|
31
|
-
createInterface: () => ({
|
|
32
|
-
question: (_q, cb) => cb(nextAnswer),
|
|
33
|
-
close: () => { },
|
|
34
|
-
}),
|
|
35
|
-
}));
|
|
36
|
-
const create_1 = require("./create");
|
|
37
|
-
describe('runCreate', () => {
|
|
38
|
-
let tempDir;
|
|
39
|
-
let originalCwd;
|
|
40
|
-
let logSpy;
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
originalCwd = process.cwd();
|
|
43
|
-
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'flexplm-create-'));
|
|
44
|
-
process.chdir(tempDir);
|
|
45
|
-
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
46
|
-
nextAnswer = '';
|
|
47
|
-
});
|
|
48
|
-
afterEach(() => {
|
|
49
|
-
logSpy.mockRestore();
|
|
50
|
-
process.chdir(originalCwd);
|
|
51
|
-
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
52
|
-
});
|
|
53
|
-
it('writes <orgName>-transformMapping.ts with the placeholder replaced', async () => {
|
|
54
|
-
nextAnswer = 'acme';
|
|
55
|
-
await (0, create_1.runCreate)();
|
|
56
|
-
const outPath = path.join(tempDir, 'acme-transformMapping.ts');
|
|
57
|
-
expect(fs.existsSync(outPath)).toBe(true);
|
|
58
|
-
const contents = fs.readFileSync(outPath, 'utf8');
|
|
59
|
-
expect(contents).toContain("orgName: 'acme'");
|
|
60
|
-
expect(contents).not.toContain('<ORG_NAME>');
|
|
61
|
-
});
|
|
62
|
-
it('trims whitespace around the orgName input', async () => {
|
|
63
|
-
nextAnswer = ' acme ';
|
|
64
|
-
await (0, create_1.runCreate)();
|
|
65
|
-
expect(fs.existsSync(path.join(tempDir, 'acme-transformMapping.ts'))).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
it('throws when orgName is empty', async () => {
|
|
68
|
-
nextAnswer = ' ';
|
|
69
|
-
await expect((0, create_1.runCreate)()).rejects.toThrow(/orgName is required/);
|
|
70
|
-
});
|
|
71
|
-
it('refuses to overwrite an existing file', async () => {
|
|
72
|
-
const existing = path.join(tempDir, 'acme-transformMapping.ts');
|
|
73
|
-
fs.writeFileSync(existing, 'do not clobber', 'utf8');
|
|
74
|
-
nextAnswer = 'acme';
|
|
75
|
-
await expect((0, create_1.runCreate)()).rejects.toThrow(/Refusing to overwrite/);
|
|
76
|
-
expect(fs.readFileSync(existing, 'utf8')).toEqual('do not clobber');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
jest.mock('@contrail/sdk', () => ({
|
|
4
|
-
Entities: jest.fn(),
|
|
5
|
-
Files: jest.fn(),
|
|
6
|
-
login: jest.fn(),
|
|
7
|
-
}));
|
|
8
|
-
const upload_1 = require("./upload");
|
|
9
|
-
describe('parseUploadArgs', () => {
|
|
10
|
-
it('parses a bare file path', () => {
|
|
11
|
-
const opts = (0, upload_1.parseUploadArgs)(['mapping.js']);
|
|
12
|
-
expect(opts).toEqual({
|
|
13
|
-
filePath: 'mapping.js',
|
|
14
|
-
message: undefined,
|
|
15
|
-
branch: undefined,
|
|
16
|
-
skipGit: false,
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
it('parses -m commit message option', () => {
|
|
20
|
-
const opts = (0, upload_1.parseUploadArgs)(['mapping.js', '-m', 'my message']);
|
|
21
|
-
expect(opts.message).toEqual('my message');
|
|
22
|
-
expect(opts.skipGit).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
it('parses -b branch option', () => {
|
|
25
|
-
const opts = (0, upload_1.parseUploadArgs)(['mapping.js', '-b', 'feature/x']);
|
|
26
|
-
expect(opts.branch).toEqual('feature/x');
|
|
27
|
-
});
|
|
28
|
-
it('parses --skip-git flag', () => {
|
|
29
|
-
const opts = (0, upload_1.parseUploadArgs)(['mapping.js', '--skip-git']);
|
|
30
|
-
expect(opts.skipGit).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
it('accepts the legacy --skipGit alias', () => {
|
|
33
|
-
const opts = (0, upload_1.parseUploadArgs)(['mapping.js', '--skipGit']);
|
|
34
|
-
expect(opts.skipGit).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it('parses options before the file path', () => {
|
|
37
|
-
const opts = (0, upload_1.parseUploadArgs)(['-m', 'msg', '-b', 'br', 'mapping.js']);
|
|
38
|
-
expect(opts).toEqual({
|
|
39
|
-
filePath: 'mapping.js',
|
|
40
|
-
message: 'msg',
|
|
41
|
-
branch: 'br',
|
|
42
|
-
skipGit: false,
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it('parses all options together', () => {
|
|
46
|
-
const opts = (0, upload_1.parseUploadArgs)(['mapping.js', '-m', 'msg', '-b', 'br', '--skip-git']);
|
|
47
|
-
expect(opts).toEqual({
|
|
48
|
-
filePath: 'mapping.js',
|
|
49
|
-
message: 'msg',
|
|
50
|
-
branch: 'br',
|
|
51
|
-
skipGit: true,
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
it('throws when -m is missing its value', () => {
|
|
55
|
-
expect(() => (0, upload_1.parseUploadArgs)(['mapping.js', '-m'])).toThrow(/-m requires a commit message/);
|
|
56
|
-
});
|
|
57
|
-
it('throws when -b is missing its value', () => {
|
|
58
|
-
expect(() => (0, upload_1.parseUploadArgs)(['mapping.js', '-b'])).toThrow(/-b requires a branch name/);
|
|
59
|
-
});
|
|
60
|
-
it('throws on unknown option', () => {
|
|
61
|
-
expect(() => (0, upload_1.parseUploadArgs)(['mapping.js', '--bogus'])).toThrow(/Unknown option: --bogus/);
|
|
62
|
-
});
|
|
63
|
-
it('throws when an extra positional argument is supplied', () => {
|
|
64
|
-
expect(() => (0, upload_1.parseUploadArgs)(['mapping.js', 'extra.js'])).toThrow(/Unexpected argument: extra\.js/);
|
|
65
|
-
});
|
|
66
|
-
it('throws when no file path is provided', () => {
|
|
67
|
-
expect(() => (0, upload_1.parseUploadArgs)([])).toThrow(/missing <path\.js>/);
|
|
68
|
-
});
|
|
69
|
-
it('throws when only options are provided', () => {
|
|
70
|
-
expect(() => (0, upload_1.parseUploadArgs)(['--skip-git'])).toThrow(/missing <path\.js>/);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('buildCommitMessage', () => {
|
|
74
|
-
it('appends fileId to the first line of a single-line message', () => {
|
|
75
|
-
expect((0, upload_1.buildCommitMessage)('initial commit', 'abc123')).toEqual('initial commit [fileId: abc123]');
|
|
76
|
-
});
|
|
77
|
-
it('only appends fileId to the first line of a multi-line message', () => {
|
|
78
|
-
const result = (0, upload_1.buildCommitMessage)('header line\nbody line 1\nbody line 2', 'xyz');
|
|
79
|
-
expect(result).toEqual('header line [fileId: xyz]\nbody line 1\nbody line 2');
|
|
80
|
-
});
|
|
81
|
-
it('handles CRLF line endings', () => {
|
|
82
|
-
const result = (0, upload_1.buildCommitMessage)('header\r\nbody', 'fid');
|
|
83
|
-
expect(result).toEqual('header [fileId: fid]\nbody');
|
|
84
|
-
});
|
|
85
|
-
it('handles an empty message', () => {
|
|
86
|
-
expect((0, upload_1.buildCommitMessage)('', 'fid')).toEqual(' [fileId: fid]');
|
|
87
|
-
});
|
|
88
|
-
});
|
package/lib/cli/index.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/cli/index.spec.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
jest.mock('./commands/create', () => ({ runCreate: jest.fn().mockResolvedValue(undefined) }));
|
|
4
|
-
jest.mock('./commands/compile', () => ({ runCompile: jest.fn().mockResolvedValue(undefined) }));
|
|
5
|
-
jest.mock('./commands/upload', () => ({ runUpload: jest.fn().mockResolvedValue(undefined) }));
|
|
6
|
-
const create_1 = require("./commands/create");
|
|
7
|
-
const compile_1 = require("./commands/compile");
|
|
8
|
-
const upload_1 = require("./commands/upload");
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
describe('cli main dispatcher', () => {
|
|
11
|
-
let originalArgv;
|
|
12
|
-
let logSpy;
|
|
13
|
-
let errorSpy;
|
|
14
|
-
let exitSpy;
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
originalArgv = process.argv;
|
|
17
|
-
create_1.runCreate.mockClear();
|
|
18
|
-
compile_1.runCompile.mockClear();
|
|
19
|
-
upload_1.runUpload.mockClear();
|
|
20
|
-
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
21
|
-
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
22
|
-
exitSpy = jest.spyOn(process, 'exit').mockImplementation(((code) => {
|
|
23
|
-
throw new Error(`__EXIT__:${code}`);
|
|
24
|
-
}));
|
|
25
|
-
});
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
process.argv = originalArgv;
|
|
28
|
-
logSpy.mockRestore();
|
|
29
|
-
errorSpy.mockRestore();
|
|
30
|
-
exitSpy.mockRestore();
|
|
31
|
-
});
|
|
32
|
-
function setArgv(...args) {
|
|
33
|
-
process.argv = ['node', 'cli', ...args];
|
|
34
|
-
}
|
|
35
|
-
it('dispatches the create command', async () => {
|
|
36
|
-
setArgv('create');
|
|
37
|
-
await (0, index_1.main)();
|
|
38
|
-
expect(create_1.runCreate).toHaveBeenCalledTimes(1);
|
|
39
|
-
expect(compile_1.runCompile).not.toHaveBeenCalled();
|
|
40
|
-
expect(upload_1.runUpload).not.toHaveBeenCalled();
|
|
41
|
-
});
|
|
42
|
-
it('dispatches the compile command with its argument', async () => {
|
|
43
|
-
setArgv('compile', 'mapping.ts');
|
|
44
|
-
await (0, index_1.main)();
|
|
45
|
-
expect(compile_1.runCompile).toHaveBeenCalledWith('mapping.ts');
|
|
46
|
-
});
|
|
47
|
-
it('exits when compile is missing its argument', async () => {
|
|
48
|
-
setArgv('compile');
|
|
49
|
-
await expect((0, index_1.main)()).rejects.toThrow('__EXIT__:1');
|
|
50
|
-
expect(compile_1.runCompile).not.toHaveBeenCalled();
|
|
51
|
-
expect(errorSpy).toHaveBeenCalledWith(expect.stringMatching(/missing <path\.ts>/));
|
|
52
|
-
});
|
|
53
|
-
it('dispatches the upload command and forwards remaining args', async () => {
|
|
54
|
-
setArgv('upload', 'mapping.js', '-m', 'msg', '--skip-git');
|
|
55
|
-
await (0, index_1.main)();
|
|
56
|
-
expect(upload_1.runUpload).toHaveBeenCalledWith(['mapping.js', '-m', 'msg', '--skip-git']);
|
|
57
|
-
});
|
|
58
|
-
it('exits when upload is missing its argument', async () => {
|
|
59
|
-
setArgv('upload');
|
|
60
|
-
await expect((0, index_1.main)()).rejects.toThrow('__EXIT__:1');
|
|
61
|
-
expect(upload_1.runUpload).not.toHaveBeenCalled();
|
|
62
|
-
expect(errorSpy).toHaveBeenCalledWith(expect.stringMatching(/missing <path\.js>/));
|
|
63
|
-
});
|
|
64
|
-
it.each(['help', '-h', '--help'])('prints usage for %s', async (helpFlag) => {
|
|
65
|
-
setArgv(helpFlag);
|
|
66
|
-
await (0, index_1.main)();
|
|
67
|
-
expect(logSpy).toHaveBeenCalledWith(expect.stringMatching(/Usage: flexplm-mapping/));
|
|
68
|
-
});
|
|
69
|
-
it('prints usage when no command is provided', async () => {
|
|
70
|
-
setArgv();
|
|
71
|
-
await (0, index_1.main)();
|
|
72
|
-
expect(logSpy).toHaveBeenCalledWith(expect.stringMatching(/Usage: flexplm-mapping/));
|
|
73
|
-
});
|
|
74
|
-
it('exits on an unknown command', async () => {
|
|
75
|
-
setArgv('bogus');
|
|
76
|
-
await expect((0, index_1.main)()).rejects.toThrow('__EXIT__:1');
|
|
77
|
-
expect(errorSpy).toHaveBeenCalledWith(expect.stringMatching(/Unknown command: bogus/));
|
|
78
|
-
});
|
|
79
|
-
});
|