Skip to content

Commit 72debf0

Browse files
committed
Bug fixes and eslint improvements
1 parent e3ef4ae commit 72debf0

4 files changed

Lines changed: 39 additions & 26 deletions

File tree

.eslintrc.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@
99
"warn",
1010
"always"
1111
],
12-
"perfectionist/sort-classes": [
13-
"off"
14-
],
12+
"perfectionist/sort-classes": "off",
13+
"perfectionist/sort-interfaces": "off",
14+
"perfectionist/sort-enums": "off",
15+
"perfectionist/sort-objects": "off",
16+
"perfectionist/sort-object-types": "off",
17+
"unicorn/no-array-reduce": "off",
18+
"unicorn/no-array-for-each": "off",
19+
"unicorn/prefer-object-from-entries": "off",
20+
"unicorn/prefer-type-error": "off",
21+
"no-await-in-loop": "off",
1522
"quotes": [
1623
"error",
1724
"single"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-test",
3-
"version": "0.0.6",
3+
"version": "0.0.11",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/plugin-tester.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
InitializeResponseData,
55
IpcMessageSchema,
66
MessageCmd,
7-
ParameterOperation,
87
PlanRequestData,
98
PlanResponseData,
109
ResourceConfig,
@@ -53,7 +52,7 @@ export class PluginTester {
5352
this.handleSudoRequests(this.childProcess);
5453
}
5554

56-
async fullTest(configs: ResourceConfig[], assertPlans?: (plans: PlanResponseData[]) => void): Promise<void> {
55+
async fullTest(configs: ResourceConfig[], skipUninstall = false, assertPlans?: (plans: PlanResponseData[]) => void): Promise<void> {
5756
const initializeResult = await this.initialize();
5857

5958
const unsupportedConfigs = configs.filter((c) =>
@@ -105,38 +104,45 @@ export class PluginTester {
105104
${JSON.stringify(unsuccessfulPlans, null, 2)}`
106105
)
107106
}
107+
108+
if (!skipUninstall) {
109+
await this.uninstall(configs.toReversed());
110+
}
108111
}
109112

110113
async uninstall(configs: ResourceConfig[]) {
114+
const plans = [];
115+
111116
for (const config of configs) {
112-
const { dependsOn, name, type, ...parameters } = config
117+
plans.push(await this.plan({
118+
desired: undefined,
119+
isStateful: true,
120+
state: config
121+
}))
122+
}
123+
124+
for (const plan of plans) {
125+
if (plan.operation !== ResourceOperation.DESTROY) {
126+
throw new Error(`Expect resource operation to be 'destory' but instead received plan: \n ${JSON.stringify(plan, null, 2)}`)
127+
}
113128

114129
await this.apply({
115-
plan: {
116-
operation: ResourceOperation.DESTROY,
117-
parameters: Object.entries(parameters).map(([key, value]) => ({
118-
name: key,
119-
newValue: null,
120-
operation: ParameterOperation.REMOVE,
121-
previousValue: value,
122-
})),
123-
resourceType: type,
124-
}
130+
planId: plan.planId
125131
});
132+
}
126133

127-
// Validate that the destroy was successful
134+
// Validate that the destroy was successful
135+
for (const config of configs) {
128136
const validationPlan = await this.plan({
129137
desired: config,
130-
state: undefined,
131-
isStateful: false,
132-
});
138+
isStateful: true,
139+
state: undefined
140+
})
133141
if (validationPlan.operation !== ResourceOperation.CREATE) {
134-
throw new Error(`Resource ${type} was not successfully destroyed.
142+
throw new Error(`Resource was not successfully destroyed.
135143
Validation plan shows:
136144
${JSON.stringify(validationPlan, null, 2)}
137-
Previous config:
138-
${JSON.stringify(config, null, 2)}`
139-
);
145+
`);
140146
}
141147
}
142148
}

test/plugin-tester.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('Plugin tester integration tests', () => {
139139
propA: 'a',
140140
propB: 10,
141141
propC: 'c',
142-
}], (plans) => {
142+
}], false, (plans) => {
143143
expect(plans[0]).toMatchObject({
144144
planId: expect.any(String),
145145
operation: ResourceOperation.NOOP,

0 commit comments

Comments
 (0)