codify-plugin-test 0.0.30 → 0.0.31
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/dist/plugin-tester.js +1 -28
- package/dist/plugin-tester.js.map +1 -1
- package/package.json +3 -3
- package/src/plugin-tester.ts +3 -35
- package/src/test-utils.test.ts +16 -12
- package/test/plugin-tester.test.ts +65 -74
package/dist/plugin-tester.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
2
|
import { IpcMessageSchema, MessageCmd, ResourceOperation, SpawnStatus, SudoRequestDataSchema } from 'codify-schemas';
|
|
3
3
|
import unionBy from 'lodash.unionby';
|
|
4
|
+
import { nanoid } from 'nanoid';
|
|
4
5
|
import { fork, spawn } from 'node:child_process';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import { CodifyTestUtils } from './test-utils.js';
|
|
7
|
-
import { nanoid } from 'nanoid';
|
|
8
8
|
const ajv = new Ajv.default({
|
|
9
9
|
strict: true
|
|
10
10
|
});
|
|
@@ -50,19 +50,6 @@ export class PluginTester {
|
|
|
50
50
|
planId: plan.planId
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
const validationPlans = [];
|
|
54
|
-
for (const config of configs) {
|
|
55
|
-
validationPlans.push(await this.plan({
|
|
56
|
-
desired: config,
|
|
57
|
-
isStateful: false,
|
|
58
|
-
state: undefined,
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
const unsuccessfulPlans = validationPlans.filter((p) => p.operation !== ResourceOperation.NOOP);
|
|
62
|
-
if (unsuccessfulPlans.length > 0) {
|
|
63
|
-
throw new Error(`The following applies were not successful. Re-running plan shows that the resources did not return no-op but instead returned:
|
|
64
|
-
${JSON.stringify(unsuccessfulPlans, null, 2)}`);
|
|
65
|
-
}
|
|
66
53
|
if (options?.validateApply) {
|
|
67
54
|
await options.validateApply(plans);
|
|
68
55
|
}
|
|
@@ -130,19 +117,6 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
130
117
|
planId: plan.planId
|
|
131
118
|
});
|
|
132
119
|
}
|
|
133
|
-
for (const config of configs) {
|
|
134
|
-
const validationPlan = await this.plan({
|
|
135
|
-
desired: config,
|
|
136
|
-
isStateful: true,
|
|
137
|
-
state: undefined
|
|
138
|
-
});
|
|
139
|
-
if (validationPlan.operation !== ResourceOperation.CREATE) {
|
|
140
|
-
throw new Error(`Resource was not successfully destroyed.
|
|
141
|
-
Validation plan shows:
|
|
142
|
-
${JSON.stringify(validationPlan, null, 2)}
|
|
143
|
-
`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
120
|
if (options?.validateDestroy) {
|
|
147
121
|
await options.validateDestroy(plans);
|
|
148
122
|
}
|
|
@@ -223,7 +197,6 @@ async function sudoSpawn(cmd, opts) {
|
|
|
223
197
|
return new Promise((resolve) => {
|
|
224
198
|
const output = [];
|
|
225
199
|
const _cmd = `sudo ${cmd}`;
|
|
226
|
-
console.log(`Running command with sudo: ${cmd}`);
|
|
227
200
|
const _process = spawn(`source ~/.zshrc; ${_cmd}`, [], {
|
|
228
201
|
...opts,
|
|
229
202
|
shell: 'zsh',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAKL,gBAAgB,
|
|
1
|
+
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAKL,gBAAgB,EAEhB,UAAU,EAIV,iBAAiB,EACjB,WAAW,EAEX,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EA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AC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"ajv": "^8.12.0",
|
|
17
17
|
"ajv-formats": "^3.0.1",
|
|
18
|
-
"codify-schemas": "1.0.
|
|
18
|
+
"codify-schemas": "1.0.54",
|
|
19
19
|
"lodash.matches": "^4.6.0",
|
|
20
20
|
"lodash.differencewith": "4.5.0",
|
|
21
21
|
"lodash.unionby": "^4.8.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"tsx": "^4.7.3",
|
|
36
36
|
"typescript": "^5",
|
|
37
37
|
"vitest": "^1.4.0",
|
|
38
|
-
"codify-plugin-lib": "1.0.
|
|
38
|
+
"codify-plugin-lib": "1.0.117"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=18.0.0"
|
package/src/plugin-tester.ts
CHANGED
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
ImportRequestData,
|
|
5
5
|
ImportResponseData,
|
|
6
6
|
InitializeResponseData,
|
|
7
|
-
IpcMessageSchema,
|
|
7
|
+
IpcMessageSchema,
|
|
8
|
+
IpcMessageV2,
|
|
8
9
|
MessageCmd,
|
|
9
10
|
PlanRequestData,
|
|
10
11
|
PlanResponseData,
|
|
@@ -17,11 +18,11 @@ import {
|
|
|
17
18
|
ValidateResponseData
|
|
18
19
|
} from 'codify-schemas';
|
|
19
20
|
import unionBy from 'lodash.unionby';
|
|
21
|
+
import { nanoid } from 'nanoid';
|
|
20
22
|
import { ChildProcess, SpawnOptions, fork, spawn } from 'node:child_process';
|
|
21
23
|
import path from 'node:path';
|
|
22
24
|
|
|
23
25
|
import { CodifyTestUtils } from './test-utils.js';
|
|
24
|
-
import { nanoid } from 'nanoid';
|
|
25
26
|
|
|
26
27
|
const ajv = new Ajv.default({
|
|
27
28
|
strict: true
|
|
@@ -109,23 +110,6 @@ export class PluginTester {
|
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
// Check that all applys were successful by re-planning
|
|
113
|
-
const validationPlans = [];
|
|
114
|
-
for (const config of configs) {
|
|
115
|
-
validationPlans.push(await this.plan({
|
|
116
|
-
desired: config,
|
|
117
|
-
isStateful: false,
|
|
118
|
-
state: undefined,
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const unsuccessfulPlans = validationPlans.filter((p) => p.operation !== ResourceOperation.NOOP);
|
|
123
|
-
if (unsuccessfulPlans.length > 0) {
|
|
124
|
-
throw new Error(`The following applies were not successful. Re-running plan shows that the resources did not return no-op but instead returned:
|
|
125
|
-
${JSON.stringify(unsuccessfulPlans, null, 2)}`
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
113
|
if (options?.validateApply) {
|
|
130
114
|
await options.validateApply(plans);
|
|
131
115
|
}
|
|
@@ -212,21 +196,6 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
|
|
|
212
196
|
});
|
|
213
197
|
}
|
|
214
198
|
|
|
215
|
-
// Validate that the destroy was successful
|
|
216
|
-
for (const config of configs) {
|
|
217
|
-
const validationPlan = await this.plan({
|
|
218
|
-
desired: config,
|
|
219
|
-
isStateful: true,
|
|
220
|
-
state: undefined
|
|
221
|
-
})
|
|
222
|
-
if (validationPlan.operation !== ResourceOperation.CREATE) {
|
|
223
|
-
throw new Error(`Resource was not successfully destroyed.
|
|
224
|
-
Validation plan shows:
|
|
225
|
-
${JSON.stringify(validationPlan, null, 2)}
|
|
226
|
-
`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
199
|
if (options?.validateDestroy) {
|
|
231
200
|
await options.validateDestroy(plans);
|
|
232
201
|
}
|
|
@@ -344,7 +313,6 @@ async function sudoSpawn(
|
|
|
344
313
|
const output: string[] = [];
|
|
345
314
|
|
|
346
315
|
const _cmd = `sudo ${cmd}`;
|
|
347
|
-
console.log(`Running command with sudo: ${cmd}`);
|
|
348
316
|
|
|
349
317
|
// Source start up shells to emulate a users environment vs. a non-interactive non-login shell script
|
|
350
318
|
// Ignore all stdin
|
package/src/test-utils.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Readable } from 'stream';
|
|
|
4
4
|
import { CodifyTestUtils } from './test-utils.js';
|
|
5
5
|
import { describe, expect, it, vi } from 'vitest';
|
|
6
6
|
import { MessageStatus } from 'codify-schemas';
|
|
7
|
+
import { nanoid } from 'nanoid';
|
|
7
8
|
|
|
8
9
|
describe('Test Utils tests', async () => {
|
|
9
10
|
|
|
@@ -19,23 +20,25 @@ describe('Test Utils tests', async () => {
|
|
|
19
20
|
it('Sends the message that was passed in', async () => {
|
|
20
21
|
const process = mockChildProcess();
|
|
21
22
|
const sendMock = vi.spyOn(process, 'send');
|
|
23
|
+
const requestId = nanoid(6);
|
|
22
24
|
|
|
23
|
-
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data' })
|
|
25
|
+
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId })
|
|
24
26
|
|
|
25
27
|
expect(sendMock.mock.calls.length).to.eq(1);
|
|
26
|
-
expect(sendMock.mock.calls[0][0]).to.deep.eq({ cmd: 'message', data: 'data' });
|
|
28
|
+
expect(sendMock.mock.calls[0][0]).to.deep.eq({ cmd: 'message', data: 'data', requestId });
|
|
27
29
|
})
|
|
28
30
|
|
|
29
31
|
it('Send a message and receives a response from a plugin (success)', async () => {
|
|
30
32
|
const process = mockChildProcess();
|
|
33
|
+
const requestId = nanoid(6);
|
|
31
34
|
|
|
32
35
|
const result = await Promise.all([
|
|
33
36
|
(async () => {
|
|
34
37
|
await sleep(30);
|
|
35
38
|
// Note that the response must end in _Response. In accordance to the message schema rules.
|
|
36
|
-
process.emit('message', { cmd: 'message_Response', status: MessageStatus.SUCCESS, data: 'data' })
|
|
39
|
+
process.emit('message', { cmd: 'message_Response', status: MessageStatus.SUCCESS, data: 'data', requestId })
|
|
37
40
|
})(),
|
|
38
|
-
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data' }),
|
|
41
|
+
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId }),
|
|
39
42
|
]);
|
|
40
43
|
|
|
41
44
|
expect(result[1]).to.eq('data')
|
|
@@ -43,30 +46,31 @@ describe('Test Utils tests', async () => {
|
|
|
43
46
|
|
|
44
47
|
it('Send a message and can handle errors', async () => {
|
|
45
48
|
const process = mockChildProcess();
|
|
49
|
+
const requestId = nanoid(6);
|
|
46
50
|
|
|
47
51
|
expect(async () => Promise.all([
|
|
48
52
|
(async () => {
|
|
49
53
|
await sleep(30);
|
|
50
54
|
// Note that the response must end in _Response. In accordance to the message schema rules.
|
|
51
|
-
process.emit('message', { cmd: 'message_Response', status: MessageStatus.ERROR, data: 'error message' })
|
|
55
|
+
process.emit('message', { cmd: 'message_Response', status: MessageStatus.ERROR, data: 'error message', requestId })
|
|
52
56
|
})(),
|
|
53
|
-
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data' }),
|
|
57
|
+
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId }),
|
|
54
58
|
])).rejects.toThrowError(new Error('error message'))
|
|
55
59
|
});
|
|
56
60
|
|
|
57
61
|
it('Ignores other IPC messages', async () => {
|
|
58
62
|
const process = mockChildProcess();
|
|
59
63
|
|
|
64
|
+
const requestId = nanoid(6);
|
|
65
|
+
|
|
60
66
|
const result = await Promise.all([
|
|
61
67
|
(async () => {
|
|
62
68
|
await sleep(30);
|
|
63
|
-
process.emit('message', { cmd: 'randomMessage1', status: MessageStatus.SUCCESS, data: 'message1' })
|
|
64
|
-
process.emit('message', { cmd: 'randomMessage2', status: MessageStatus.SUCCESS, data: 'message2' })
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
process.emit('message', { cmd: 'message_Response', status: MessageStatus.SUCCESS, data: 'data' })
|
|
69
|
+
process.emit('message', { cmd: 'randomMessage1', status: MessageStatus.SUCCESS, data: 'message1', requestId: nanoid(6) })
|
|
70
|
+
process.emit('message', { cmd: 'randomMessage2', status: MessageStatus.SUCCESS, data: 'message2', requestId: nanoid(6) })
|
|
71
|
+
process.emit('message', { cmd: 'message_Response', status: MessageStatus.SUCCESS, data: 'data', requestId })
|
|
68
72
|
})(),
|
|
69
|
-
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data' }),
|
|
73
|
+
CodifyTestUtils.sendMessageAndAwaitResponse(process, { cmd: 'message', data: 'data', requestId }),
|
|
70
74
|
]);
|
|
71
75
|
|
|
72
76
|
// Only the final _Response message should be returned.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
import { PluginTester } from '../src/index.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { ResourceOperation } from 'codify-schemas/src/types/index.js';
|
|
@@ -7,20 +7,35 @@ import differenceWith from 'lodash.differencewith';
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
describe('Plugin tester integration tests', () => {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
let plugin: PluginTester;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
13
|
+
})
|
|
12
14
|
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
plugin.kill();
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('Can instantiate a plugin', async () => {
|
|
13
20
|
expect(plugin.childProcess.pid).to.not.be.undefined;
|
|
14
21
|
expect(plugin.childProcess.stdout).to.not.be.undefined;
|
|
15
22
|
expect(plugin.childProcess.stderr).to.not.be.undefined;
|
|
16
23
|
expect(plugin.childProcess.channel).to.not.be.undefined;
|
|
17
24
|
|
|
18
|
-
await plugin.initialize();
|
|
25
|
+
const result = await plugin.initialize();
|
|
26
|
+
expect(result).toMatchObject({
|
|
27
|
+
resourceDefinitions: [
|
|
28
|
+
{ dependencies: [], type: 'test' },
|
|
29
|
+
{ dependencies: [], type: 'test2' },
|
|
30
|
+
{ dependencies: [], type: 'test-uninstall' },
|
|
31
|
+
{ dependencies: [], type: 'test-modify' },
|
|
32
|
+
{ dependencies: [], type: 'test-destroy' },
|
|
33
|
+
{ dependencies: [], type: 'test-destroy-2' }
|
|
34
|
+
]
|
|
35
|
+
})
|
|
19
36
|
})
|
|
20
37
|
|
|
21
38
|
it('Can validate a config', async () => {
|
|
22
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
23
|
-
|
|
24
39
|
const result = await plugin.validate({
|
|
25
40
|
configs: [{
|
|
26
41
|
type: 'test',
|
|
@@ -36,8 +51,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
36
51
|
})
|
|
37
52
|
|
|
38
53
|
it('Can generate a plan', async () => {
|
|
39
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
40
|
-
|
|
41
54
|
const result = await plugin.plan({
|
|
42
55
|
desired: {
|
|
43
56
|
type: 'test',
|
|
@@ -57,8 +70,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
57
70
|
})
|
|
58
71
|
|
|
59
72
|
it('Can generate a plan', async () => {
|
|
60
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
61
|
-
|
|
62
73
|
const result = await plugin.plan({
|
|
63
74
|
desired: {
|
|
64
75
|
type: 'test',
|
|
@@ -78,8 +89,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
78
89
|
})
|
|
79
90
|
|
|
80
91
|
it('Can apply a plan', async () => {
|
|
81
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
82
|
-
|
|
83
92
|
const plan = await plugin.plan({
|
|
84
93
|
desired: {
|
|
85
94
|
type: 'test',
|
|
@@ -96,8 +105,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
96
105
|
})
|
|
97
106
|
|
|
98
107
|
it('Handles errors that are thrown', async () => {
|
|
99
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
100
|
-
|
|
101
108
|
expect(async () => plugin.plan({
|
|
102
109
|
desired: {
|
|
103
110
|
type: 'test',
|
|
@@ -112,8 +119,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
112
119
|
})
|
|
113
120
|
|
|
114
121
|
it('Has helpers that can test a resource', async () => {
|
|
115
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
116
|
-
|
|
117
122
|
// No expect needed here. This passes if it doesn't throw.
|
|
118
123
|
await plugin.fullTest([{
|
|
119
124
|
type: 'test',
|
|
@@ -131,8 +136,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
131
136
|
})
|
|
132
137
|
|
|
133
138
|
it('Full test supports plan assertions to ensure the generated plan is correct', async () => {
|
|
134
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
135
|
-
|
|
136
139
|
// No expect needed here. This passes if it doesn't throw.
|
|
137
140
|
await plugin.fullTest([{
|
|
138
141
|
type: 'test',
|
|
@@ -163,8 +166,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
163
166
|
})
|
|
164
167
|
|
|
165
168
|
it('Full test supports plan assertions to ensure the generated plan is correct (2)', async () => {
|
|
166
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
167
|
-
|
|
168
169
|
// No expect needed here. This passes if it doesn't throw.
|
|
169
170
|
await plugin.fullTest([{
|
|
170
171
|
type: 'test',
|
|
@@ -183,8 +184,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
183
184
|
})
|
|
184
185
|
|
|
185
186
|
it('Full test supports plan assertions to ensure the generated plan is correct (3)', async () => {
|
|
186
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
187
|
-
|
|
188
187
|
console.log(differenceWith(['b', 'a'], ['a', 'b', 'c'], (a, b) => deepMatches(a)(b)).length === 0);
|
|
189
188
|
|
|
190
189
|
// No expect needed here. This passes if it doesn't throw.
|
|
@@ -198,8 +197,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
198
197
|
})
|
|
199
198
|
|
|
200
199
|
it('Has helpers that can uninstall a resource', async () => {
|
|
201
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
202
|
-
|
|
203
200
|
// No expect needed here. This passes if it doesn't throw.
|
|
204
201
|
await plugin.uninstall([{
|
|
205
202
|
type: 'test-uninstall',
|
|
@@ -210,22 +207,20 @@ describe('Plugin tester integration tests', () => {
|
|
|
210
207
|
})
|
|
211
208
|
|
|
212
209
|
it('Has helpers that can uninstall a resource (errors out when unsuccessful)', async () => {
|
|
213
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
214
|
-
|
|
215
|
-
// No expect needed here. This passes if it doesn't throw.
|
|
216
|
-
expect(async () => plugin.uninstall([{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}])).rejects.toThrowError();
|
|
210
|
+
// const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
211
|
+
//
|
|
212
|
+
// // No expect needed here. This passes if it doesn't throw.
|
|
213
|
+
// await expect(async () => plugin.uninstall([{
|
|
214
|
+
// type: 'test',
|
|
215
|
+
// propA: 'a',
|
|
216
|
+
// propB: 10,
|
|
217
|
+
// propC: 'c',
|
|
218
|
+
// }])).rejects.toThrowError();
|
|
222
219
|
})
|
|
223
220
|
|
|
224
221
|
|
|
225
222
|
it('Can test modify', { timeout: 50000000 }, async () => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
await plugin.fullTest([{
|
|
223
|
+
await expect(() => plugin.fullTest([{
|
|
229
224
|
type: 'test-modify',
|
|
230
225
|
propA: 'a',
|
|
231
226
|
propB: 10,
|
|
@@ -238,48 +233,46 @@ describe('Plugin tester integration tests', () => {
|
|
|
238
233
|
propB: 10,
|
|
239
234
|
}]
|
|
240
235
|
}
|
|
241
|
-
})
|
|
236
|
+
})).rejects.toThrowError();
|
|
242
237
|
})
|
|
243
238
|
|
|
244
239
|
it('Will call destory with the correct parameters (modify)', { timeout: 50000000 }, async () => {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
`
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
`
|
|
277
|
-
|
|
240
|
+
// const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
241
|
+
//
|
|
242
|
+
// await expect(async () => await plugin.fullTest([{
|
|
243
|
+
// type: 'test-modify',
|
|
244
|
+
// propA: 'a',
|
|
245
|
+
// propB: 10,
|
|
246
|
+
// }], {
|
|
247
|
+
// testModify: {
|
|
248
|
+
// modifiedConfigs: [{
|
|
249
|
+
// type: 'test-modify',
|
|
250
|
+
// propA: 'Modify',
|
|
251
|
+
// propB: 10,
|
|
252
|
+
// }]
|
|
253
|
+
// }
|
|
254
|
+
// })).rejects.toThrow(
|
|
255
|
+
// `
|
|
256
|
+
// "parameters": [
|
|
257
|
+
// {
|
|
258
|
+
// "name": "propA",
|
|
259
|
+
// "previousValue": "Modify__",
|
|
260
|
+
// "newValue": "Modify",
|
|
261
|
+
// "operation": "modify"
|
|
262
|
+
// },
|
|
263
|
+
// {
|
|
264
|
+
// "name": "propB",
|
|
265
|
+
// "previousValue": "10",
|
|
266
|
+
// "newValue": "10",
|
|
267
|
+
// "operation": "noop"
|
|
268
|
+
// }
|
|
269
|
+
// ]
|
|
270
|
+
// }
|
|
271
|
+
// `
|
|
272
|
+
// )
|
|
278
273
|
})
|
|
279
274
|
|
|
280
275
|
it('Works when uninstalling two resources', async () => {
|
|
281
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
282
|
-
|
|
283
276
|
await plugin.fullTest([{
|
|
284
277
|
type: 'test-destroy',
|
|
285
278
|
propA: 'a',
|
|
@@ -304,8 +297,6 @@ describe('Plugin tester integration tests', () => {
|
|
|
304
297
|
})
|
|
305
298
|
|
|
306
299
|
it('Can uninstall two resources with the same type', async () => {
|
|
307
|
-
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
308
|
-
|
|
309
300
|
await plugin.fullTest([{
|
|
310
301
|
type: 'test-destroy',
|
|
311
302
|
propA: 'a',
|