@squiz/dxp-cli-next 5.10.0-develop.5 → 5.10.0-develop.6

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.
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ declare const createClearCommand: () => Command;
3
+ export default createClearCommand;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = require("commander");
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const ora_1 = __importDefault(require("ora"));
18
+ const utils_1 = require("../../utils");
19
+ const utils_2 = require("../utils");
20
+ const createClearCommand = () => {
21
+ const clearCommand = new commander_1.Command('clear')
22
+ .name('clear')
23
+ .description('Clears a datastore simulator')
24
+ .addOption(new commander_1.Option('-b, --blueprint <string>', 'Path to your datastore API yaml file.').makeOptionMandatory())
25
+ .addOption(new commander_1.Option('-f, --force', 'Force the removal of the datastore simulator'))
26
+ .configureOutput({
27
+ outputError(str, write) {
28
+ write(chalk_1.default.red(str));
29
+ },
30
+ })
31
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
32
+ console.log('');
33
+ const spinner = (0, ora_1.default)();
34
+ try {
35
+ yield (0, utils_2.checkUpdateAvailable)();
36
+ yield (0, utils_2.checkDockerInstalled)();
37
+ const forceMessage = 'Clearing data can not be undone. Are you sure you want to continue? (y/N)';
38
+ if (!options.force) {
39
+ if ((yield (0, utils_2.forcePrompt)(forceMessage, false)) === false) {
40
+ const clearGuide = `To clear run:\n $ dxp-next datastore simulator clear --blueprint ${options.blueprint} --force\n`;
41
+ throw new Error(clearGuide);
42
+ }
43
+ }
44
+ spinner.start('Clearing data.');
45
+ const { fullPath, dirPath, yamlFile, containerName } = (0, utils_2.getSimulatorDetails)(options.blueprint);
46
+ const clearCommand = `docker exec ${containerName} clear-data`;
47
+ const containerCommand = yield (0, utils_2.executeCommand)(`docker ps -a --filter "name=${containerName}" --format "{{.Names}}"`);
48
+ if (containerCommand === '') {
49
+ throw new Error('Sorry, no simulator container found for that blueprint path. Please try again using a different path.');
50
+ }
51
+ try {
52
+ yield (0, utils_2.executeCommand)(clearCommand);
53
+ }
54
+ catch (error) {
55
+ console.error(error);
56
+ (0, utils_1.logDebug)(`ERROR: ${JSON.stringify(error)}`);
57
+ throw new Error('Unable to clear data.');
58
+ }
59
+ spinner.succeed(`Done! Cleared all test data for container ID "${containerName}".`);
60
+ return;
61
+ }
62
+ catch (error) {
63
+ (0, utils_1.logDebug)(`ERROR: ${JSON.stringify(error)}`);
64
+ spinner.fail();
65
+ (0, utils_1.handleCommandError)(clearCommand, error);
66
+ }
67
+ }));
68
+ return clearCommand;
69
+ };
70
+ exports.default = createClearCommand;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,224 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const clear_1 = __importDefault(require("./clear"));
39
+ const utils = __importStar(require("../utils"));
40
+ const chalk_1 = __importDefault(require("chalk"));
41
+ const logSpy = jest.spyOn(global.console, 'log');
42
+ const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {
43
+ return undefined;
44
+ }); // prevent process exit on error
45
+ beforeEach(() => {
46
+ jest.resetAllMocks();
47
+ });
48
+ describe('datastoreSimulatorClear', () => {
49
+ it('should not clear if prompt returns false', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const checkUpdateAvailableSpy = jest
51
+ .spyOn(utils, 'checkUpdateAvailable')
52
+ .mockImplementation(() => {
53
+ return Promise.resolve(null);
54
+ });
55
+ const forcePromptSpy = jest
56
+ .spyOn(utils, 'forcePrompt')
57
+ .mockResolvedValue(false);
58
+ let executeCommandCount = 0;
59
+ const executeCommandSpy = jest
60
+ .spyOn(utils, 'executeCommand')
61
+ .mockImplementation((cmd, opt) => {
62
+ executeCommandCount++;
63
+ switch (executeCommandCount) {
64
+ case 1:
65
+ expect(cmd).toStrictEqual('docker -v');
66
+ return Promise.resolve('Docker version 20.10.23, build 7155243');
67
+ }
68
+ return Promise.reject(false);
69
+ });
70
+ const program = (0, clear_1.default)();
71
+ const commandErrorSpy = jest.spyOn(program, 'error');
72
+ yield program.parseAsync([
73
+ 'node',
74
+ 'dxp-cli',
75
+ 'datastore',
76
+ 'simulator',
77
+ 'clear',
78
+ '-b',
79
+ '/path/to/blueprint.yaml',
80
+ ]);
81
+ const opts = program.opts();
82
+ expect(opts.blueprint).toEqual('/path/to/blueprint.yaml');
83
+ expect(checkUpdateAvailableSpy).toHaveBeenCalledTimes(1);
84
+ expect(commandErrorSpy).toHaveBeenCalledWith(chalk_1.default.red(`To clear run:
85
+ $ dxp-next datastore simulator clear --blueprint /path/to/blueprint.yaml --force
86
+ `));
87
+ expect(forcePromptSpy).toHaveBeenCalledWith('Clearing data can not be undone. Are you sure you want to continue? (y/N)', false);
88
+ expect(logSpy).toHaveBeenCalledTimes(1);
89
+ expect(executeCommandSpy).toHaveBeenCalledTimes(1);
90
+ }));
91
+ it('should clear data if --force set', () => __awaiter(void 0, void 0, void 0, function* () {
92
+ const checkUpdateAvailableSpy = jest
93
+ .spyOn(utils, 'checkUpdateAvailable')
94
+ .mockImplementation(() => {
95
+ return Promise.resolve(null);
96
+ });
97
+ const forcePromptSpy = jest
98
+ .spyOn(utils, 'forcePrompt')
99
+ .mockResolvedValue(true);
100
+ let executeCommandCount = 0;
101
+ const executeCommandSpy = jest
102
+ .spyOn(utils, 'executeCommand')
103
+ .mockImplementation((cmd, opt) => {
104
+ executeCommandCount++;
105
+ switch (executeCommandCount) {
106
+ case 1:
107
+ expect(cmd).toStrictEqual('docker -v');
108
+ return Promise.resolve('Docker version 20.10.23, build 7155243');
109
+ case 2:
110
+ expect(cmd).toStrictEqual('docker ps -a --filter "name=datastore-sim-119726bb" --format "{{.Names}}"');
111
+ return Promise.resolve('datastore-sim-119726bb');
112
+ case 3:
113
+ expect(cmd).toStrictEqual('docker exec datastore-sim-119726bb clear-data');
114
+ return Promise.resolve('');
115
+ }
116
+ return Promise.reject(false);
117
+ });
118
+ const program = (0, clear_1.default)();
119
+ const commandErrorSpy = jest.spyOn(program, 'error');
120
+ yield program.parseAsync([
121
+ 'node',
122
+ 'dxp-cli',
123
+ 'datastore',
124
+ 'simulator',
125
+ 'clear',
126
+ '-b',
127
+ '/path/to/blueprint.yaml',
128
+ '--force',
129
+ ]);
130
+ const opts = program.opts();
131
+ expect(opts.blueprint).toEqual('/path/to/blueprint.yaml');
132
+ expect(checkUpdateAvailableSpy).toHaveBeenCalledTimes(1);
133
+ expect(commandErrorSpy).not.toHaveBeenCalled();
134
+ expect(forcePromptSpy).not.toHaveBeenCalled();
135
+ expect(logSpy).toHaveBeenCalledTimes(1);
136
+ expect(executeCommandSpy).toHaveBeenCalledTimes(3);
137
+ }));
138
+ it('should clear if prompt returns true', () => __awaiter(void 0, void 0, void 0, function* () {
139
+ const checkUpdateAvailableSpy = jest
140
+ .spyOn(utils, 'checkUpdateAvailable')
141
+ .mockImplementation(() => {
142
+ return Promise.resolve(null);
143
+ });
144
+ const forcePromptSpy = jest
145
+ .spyOn(utils, 'forcePrompt')
146
+ .mockResolvedValue(true);
147
+ let executeCommandCount = 0;
148
+ const executeCommandSpy = jest
149
+ .spyOn(utils, 'executeCommand')
150
+ .mockImplementation((cmd, opt) => {
151
+ executeCommandCount++;
152
+ switch (executeCommandCount) {
153
+ case 1:
154
+ expect(cmd).toStrictEqual('docker -v');
155
+ return Promise.resolve('Docker version 20.10.23, build 7155243');
156
+ case 2:
157
+ expect(cmd).toStrictEqual('docker ps -a --filter "name=datastore-sim-119726bb" --format "{{.Names}}"');
158
+ return Promise.resolve('datastore-sim-119726bb');
159
+ case 3:
160
+ expect(cmd).toStrictEqual('docker exec datastore-sim-119726bb clear-data');
161
+ return Promise.resolve('');
162
+ }
163
+ return Promise.reject(false);
164
+ });
165
+ const program = (0, clear_1.default)();
166
+ const commandErrorSpy = jest.spyOn(program, 'error');
167
+ yield program.parseAsync([
168
+ 'node',
169
+ 'dxp-cli',
170
+ 'datastore',
171
+ 'simulator',
172
+ 'clear',
173
+ '-b',
174
+ '/path/to/blueprint.yaml',
175
+ ]);
176
+ const opts = program.opts();
177
+ expect(opts.blueprint).toEqual('/path/to/blueprint.yaml');
178
+ expect(checkUpdateAvailableSpy).toHaveBeenCalledTimes(1);
179
+ expect(commandErrorSpy).not.toHaveBeenCalled();
180
+ expect(forcePromptSpy).toHaveBeenCalledWith('Clearing data can not be undone. Are you sure you want to continue? (y/N)', false);
181
+ expect(logSpy).toHaveBeenCalledTimes(1);
182
+ expect(executeCommandSpy).toHaveBeenCalledTimes(3);
183
+ }));
184
+ it('should not clear data if no matching simulator found', () => __awaiter(void 0, void 0, void 0, function* () {
185
+ const checkUpdateAvailableSpy = jest
186
+ .spyOn(utils, 'checkUpdateAvailable')
187
+ .mockImplementation(() => {
188
+ return Promise.resolve(null);
189
+ });
190
+ let executeCommandCount = 0;
191
+ const executeCommandSpy = jest
192
+ .spyOn(utils, 'executeCommand')
193
+ .mockImplementation((cmd, opt) => {
194
+ executeCommandCount++;
195
+ switch (executeCommandCount) {
196
+ case 1:
197
+ expect(cmd).toStrictEqual('docker -v');
198
+ return Promise.resolve('Docker version 20.10.23, build 7155243');
199
+ case 2:
200
+ expect(cmd).toStrictEqual('docker ps -a --filter "name=datastore-sim-119726bb" --format "{{.Names}}"');
201
+ return Promise.resolve('');
202
+ }
203
+ return Promise.reject(false);
204
+ });
205
+ const program = (0, clear_1.default)();
206
+ const commandErrorSpy = jest.spyOn(program, 'error');
207
+ yield program.parseAsync([
208
+ 'node',
209
+ 'dxp-cli',
210
+ 'datastore',
211
+ 'simulator',
212
+ 'clear',
213
+ '-b',
214
+ '/path/to/blueprint.yaml',
215
+ '--force',
216
+ ]);
217
+ const opts = program.opts();
218
+ expect(opts.blueprint).toEqual('/path/to/blueprint.yaml');
219
+ expect(checkUpdateAvailableSpy).toHaveBeenCalledTimes(1);
220
+ expect(commandErrorSpy).toHaveBeenCalledWith(chalk_1.default.red('Sorry, no simulator container found for that blueprint path. Please try again using a different path.'));
221
+ expect(logSpy).toHaveBeenCalledTimes(1);
222
+ expect(executeCommandSpy).toHaveBeenCalledTimes(2);
223
+ }));
224
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ declare const createListCommand: () => Command;
3
+ export default createListCommand;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = require("commander");
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const ora_1 = __importDefault(require("ora"));
18
+ const utils_1 = require("../../utils");
19
+ const utils_2 = require("../utils");
20
+ const createListCommand = () => {
21
+ const listCommand = new commander_1.Command('list')
22
+ .name('list')
23
+ .description('Lists all the simulator')
24
+ .configureOutput({
25
+ outputError(str, write) {
26
+ write(chalk_1.default.red(str));
27
+ },
28
+ })
29
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
30
+ yield (0, utils_1.throwErrorIfNotLoggedIn)(listCommand);
31
+ console.log('');
32
+ const spinner = (0, ora_1.default)();
33
+ try {
34
+ yield (0, utils_2.checkUpdateAvailable)();
35
+ spinner.start('Gathering details from all simulator containers.');
36
+ yield (0, utils_2.checkDockerInstalled)();
37
+ // Check if there is any sim container at all.
38
+ const command = 'docker ps -a --filter "name=datastore-sim-*" --format "{{.Names}}"';
39
+ // cspell:disable
40
+ let simulatorVersionCmd = 'docker image inspect squizdxp/datastore:latest';
41
+ simulatorVersionCmd +=
42
+ ' --format \'{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}\'';
43
+ // cspell:enable
44
+ let currentVersion = '';
45
+ const containerCommand = yield (0, utils_2.executeCommand)(command);
46
+ if (containerCommand === '') {
47
+ spinner.succeed('No simulator blueprint found. Try adding a blueprint first.');
48
+ return;
49
+ }
50
+ else {
51
+ spinner.succeed('Done! Listing simulated blueprints:');
52
+ }
53
+ const version = yield (0, utils_2.executeCommand)(simulatorVersionCmd);
54
+ currentVersion = version.replace(/\r?\n|\r/g, '');
55
+ console.log('');
56
+ console.log(` All simulators are running on version: ${currentVersion}`);
57
+ const containerRunningCommand = yield (0, utils_2.executeCommand)('docker ps --filter "name=datastore-sim-*" --filter "status=running" --format "{{.Names}}"');
58
+ console.log(containerRunningCommand);
59
+ const observableBatch = [];
60
+ containerRunningCommand
61
+ .split(/\s+/)
62
+ .forEach((containerName) => __awaiter(void 0, void 0, void 0, function* () {
63
+ if (containerName !== '') {
64
+ observableBatch.push(`docker exec ${containerName} bash -c "cat /var/www/data/containerData.json"`
65
+ // Gather simulator info stored in a file
66
+ );
67
+ }
68
+ }));
69
+ let results = [];
70
+ if (observableBatch.length === 0) {
71
+ // If none is running return empty array so pipe can continue.
72
+ results = [];
73
+ }
74
+ else {
75
+ results = yield Promise.all(observableBatch.map((item) => (0, utils_2.executeCommand)(item)));
76
+ }
77
+ results.forEach((result) => {
78
+ console.log(result);
79
+ if (result !== '') {
80
+ const resultArray = JSON.parse(result);
81
+ console.log('');
82
+ console.log(` Container ID: ${resultArray.container}`);
83
+ console.log(` Blueprint: ${resultArray.blueprint || ''}`);
84
+ console.log(` URL: ${resultArray.url || ''}`);
85
+ console.log(` JWT URL: ${resultArray.jwt || ''}`);
86
+ console.log(' Status: Running');
87
+ console.log('');
88
+ }
89
+ });
90
+ // List paused containers, only need to get the blueprint label for paused simulators.
91
+ let pausedContainersCommand = 'docker ps --filter "name=datastore-sim-*" --filter "status=exited" ';
92
+ pausedContainersCommand +=
93
+ '--format "{{.Names}}~{{.Label \\"blueprint\\"}}#"';
94
+ results = yield (0, utils_2.executeCommand)(pausedContainersCommand);
95
+ results.split(/#\s+/).forEach((containerName) => {
96
+ if (containerName !== '') {
97
+ const containerInfo = containerName.split('~') || '';
98
+ console.log('');
99
+ console.log(` Container ID: ${containerInfo[0]}`);
100
+ console.log(` Blueprint: ${containerInfo[1] || ''}`);
101
+ console.log(' Status: Paused');
102
+ console.log('');
103
+ }
104
+ });
105
+ return;
106
+ }
107
+ catch (error) {
108
+ (0, utils_1.logDebug)(`ERROR: ${JSON.stringify(error)}`);
109
+ spinner.fail();
110
+ (0, utils_1.handleCommandError)(listCommand, error);
111
+ }
112
+ }));
113
+ if (process.env.ENABLE_OVERRIDE_DATASTORE_URL === 'true') {
114
+ listCommand.addOption(new commander_1.Option('-i, --image <string>', 'Override the docker image'));
115
+ }
116
+ return listCommand;
117
+ };
118
+ exports.default = createListCommand;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,95 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const list_1 = __importDefault(require("./list"));
39
+ const utils = __importStar(require("../utils"));
40
+ const logSpy = jest.spyOn(global.console, 'log');
41
+ jest.mock('fs', () => {
42
+ return {
43
+ existsSync: jest.fn().mockReturnValue(true),
44
+ };
45
+ });
46
+ describe('datastoreSimulatorList', () => {
47
+ it('correctly lists a simulator', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ const checkUpdateAvailableSpy = jest
49
+ .spyOn(utils, 'checkUpdateAvailable')
50
+ .mockImplementation(() => {
51
+ return Promise.resolve(null);
52
+ });
53
+ let executeCommandCount = 0;
54
+ const executeCommandSpy = jest
55
+ .spyOn(utils, 'executeCommand')
56
+ .mockImplementation((cmd, opt) => {
57
+ executeCommandCount++;
58
+ switch (executeCommandCount) {
59
+ case 1:
60
+ expect(cmd).toStrictEqual('docker -v');
61
+ return Promise.resolve('Docker version 20.10.23, build 7155243');
62
+ case 2:
63
+ expect(cmd).toStrictEqual('docker ps -a --filter "name=datastore-sim-*" --format "{{.Names}}"');
64
+ return Promise.resolve(`\~blueprint=/Users/pnolland/Documents/Work/GitRepos/blueprints/boilerplate2/api.yaml,desktop.docker.io/binds/0/Source=/Users/pnolland/Documents/Work/GitRepos/blueprints/boilerplate2,desktop.docker.io/binds/0/SourceKind=hostFile,desktop.docker.io/binds/0/Target=/var/www/instances,port=8085,squiz.datastore.version=4.0.1~
65
+ ~desktop.docker.io/binds/0/SourceKind=hostFile,desktop.docker.io/binds/0/Target=/var/www/instances,port=7002,squiz.datastore.version=4.0.1,blueprint=/Users/pnolland/Documents/Work/GitRepos/blueprints/boilerplate/api.yaml,desktop.docker.io/binds/0/Source=/Users/pnolland/Documents/Work/GitRepos/blueprints/boilerplate~
66
+ ~desktop.docker.io/binds/0/Target=/var/www/instances,port=7001,squiz.datastore.version=4.0.1,blueprint=/Users/pnolland/Documents/Work/GitRepos/datastore/apps/js-sdk/tests/test-project/api.yaml,desktop.docker.io/binds/0/Source=/Users/pnolland/Documents/Work/GitRepos/datastore/apps/js-sdk/tests/test-project,desktop.docker.io/binds/0/SourceKind=hostFile~`);
67
+ case 3:
68
+ expect(cmd).toStrictEqual('docker image inspect squizdxp/datastore:latest --format \'{{ or (index .Config.Labels "squiz.datastore.version") (printf "Unknown") }}\'');
69
+ return Promise.resolve('');
70
+ case 4:
71
+ expect(cmd).toStrictEqual('docker ps --filter "name=datastore-sim-*" --filter "status=running" --format "{{.Names}}"');
72
+ return Promise.resolve('');
73
+ case 5:
74
+ expect(cmd).toStrictEqual('docker ps --filter "name=datastore-sim-*" --filter "status=exited" --format "{{.Names}}~{{.Label \\"blueprint\\"}}#"');
75
+ return Promise.resolve(JSON.stringify([]));
76
+ }
77
+ return Promise.reject(false);
78
+ });
79
+ process.env.ENABLE_OVERRIDE_DATASTORE_URL = 'true';
80
+ const program = (0, list_1.default)();
81
+ yield program.parseAsync([
82
+ 'node',
83
+ 'dxp-cli',
84
+ 'datastore',
85
+ 'simulator',
86
+ 'list',
87
+ ]);
88
+ const opts = program.opts();
89
+ expect(checkUpdateAvailableSpy).toHaveBeenCalledTimes(1);
90
+ expect(logSpy).toHaveBeenCalledTimes(9);
91
+ expect(logSpy).toHaveBeenCalledWith('');
92
+ expect(logSpy).toHaveBeenCalledWith('');
93
+ expect(logSpy).toHaveBeenCalledWith('');
94
+ }));
95
+ });
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const commander_1 = require("commander");
7
7
  const add_1 = __importDefault(require("./add/add"));
8
8
  const remove_1 = __importDefault(require("./remove/remove"));
9
+ const list_1 = __importDefault(require("./list/list"));
10
+ const clear_1 = __importDefault(require("./clear/clear"));
9
11
  const upgrade_1 = __importDefault(require("./upgrade/upgrade"));
10
12
  const createSimulatorCommand = () => {
11
13
  const datastoreSimulatorCommand = new commander_1.Command('simulator');
@@ -13,6 +15,8 @@ const createSimulatorCommand = () => {
13
15
  .description('Datastore Simulator Commands')
14
16
  .addCommand((0, add_1.default)())
15
17
  .addCommand((0, remove_1.default)())
18
+ .addCommand((0, list_1.default)())
19
+ .addCommand((0, clear_1.default)())
16
20
  .addCommand((0, upgrade_1.default)());
17
21
  return datastoreSimulatorCommand;
18
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.10.0-develop.5",
3
+ "version": "5.10.0-develop.6",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },