@universal-packages/workflows-jest 1.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +15 -0
- package/globals.d.ts +7 -1
- package/index.js +45 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -66,6 +66,21 @@ it('should have been build and run', async () => {
|
|
66
66
|
})
|
67
67
|
```
|
68
68
|
|
69
|
+
### toHaveRanCommands
|
70
|
+
|
71
|
+
```js
|
72
|
+
import { Workflows } from '@universal-packages/workflows'
|
73
|
+
|
74
|
+
it('should be successful', async () => {
|
75
|
+
const workflow = await workflowsJest.run('my-workflow')
|
76
|
+
|
77
|
+
expect(workflow).toHaveRanCommands([
|
78
|
+
{ command: 'git pull', workingDirectory: './my-repo' },
|
79
|
+
{ command: 'npm install', workingDirectory: './my-repo' }
|
80
|
+
])
|
81
|
+
})
|
82
|
+
```
|
83
|
+
|
69
84
|
## Typescript
|
70
85
|
|
71
86
|
In order for typescript to see the global types you need to reference the types somewhere in your project, normally `./src/globals.d.ts`.
|
package/globals.d.ts
CHANGED
@@ -5,6 +5,11 @@ interface ProcessMockDescriptor {
|
|
5
5
|
workingDirectory?: string;
|
6
6
|
result: string;
|
7
7
|
}
|
8
|
+
export interface ProcessCommandEntry {
|
9
|
+
command: string;
|
10
|
+
env?: Record<string, string>;
|
11
|
+
workingDirectory?: string;
|
12
|
+
}
|
8
13
|
interface WorkflowJestRunOptions extends BuildFromOptions {
|
9
14
|
targetMockResults?: ProcessMockDescriptor[];
|
10
15
|
}
|
@@ -15,9 +20,10 @@ declare global {
|
|
15
20
|
}
|
16
21
|
namespace jest {
|
17
22
|
interface Matchers<R> {
|
18
|
-
toHaveFinishWithStatus(status: Status): R;
|
19
23
|
toHaveBeenBuildAndRun(): R;
|
20
24
|
toHaveBeenBuildAndRunWithVariables(variables: Record<string, any>): R;
|
25
|
+
toHaveFinishWithStatus(status: Status): R;
|
26
|
+
toHaveRanCommands(commands: ProcessCommandEntry[]): R;
|
21
27
|
}
|
22
28
|
}
|
23
29
|
}
|
package/index.js
CHANGED
@@ -119,9 +119,52 @@ function toHaveBeenBuildAndRunWithVariables(workflow, variables) {
|
|
119
119
|
}
|
120
120
|
}
|
121
121
|
}
|
122
|
+
function toHaveRanCommands(workflow, processCommandEntries) {
|
123
|
+
const pass = sub_process_1.TestEngine.commandHistory.every((processEntry, index) => {
|
124
|
+
const processCommandEntry = processCommandEntries[index];
|
125
|
+
if (processCommandEntry) {
|
126
|
+
const commandParts = processCommandEntry.command.split(' ');
|
127
|
+
const actualCommand = commandParts[0];
|
128
|
+
const actualArgs = commandParts.slice(1);
|
129
|
+
return (this.equals(actualCommand, processEntry.command) &&
|
130
|
+
this.equals(actualArgs, processEntry.args) &&
|
131
|
+
this.equals(processCommandEntry.env || {}, processEntry.env) &&
|
132
|
+
this.equals(processCommandEntry.workingDirectory, processEntry.workingDirectory));
|
133
|
+
}
|
134
|
+
return false;
|
135
|
+
});
|
136
|
+
if (pass) {
|
137
|
+
return {
|
138
|
+
message: () => `expected "${workflow.name || 'Workflow'}" not to have ran provided commands, but it did exactly that`,
|
139
|
+
pass
|
140
|
+
};
|
141
|
+
}
|
142
|
+
else {
|
143
|
+
const generatedFromHistory = sub_process_1.TestEngine.commandHistory.map((processEntry) => {
|
144
|
+
return {
|
145
|
+
command: processEntry.command + (processEntry.args.length > 0 ? ' ' + processEntry.args.join(' ') : ''),
|
146
|
+
env: processEntry.env,
|
147
|
+
workingDirectory: processEntry.workingDirectory
|
148
|
+
};
|
149
|
+
});
|
150
|
+
const generatedFromEntries = processCommandEntries.map((processCommandEntry) => {
|
151
|
+
return {
|
152
|
+
command: processCommandEntry.command,
|
153
|
+
env: processCommandEntry.env || {},
|
154
|
+
workingDirectory: processCommandEntry.workingDirectory
|
155
|
+
};
|
156
|
+
});
|
157
|
+
const commandsToPrint = this.utils.diff(generatedFromHistory, generatedFromEntries);
|
158
|
+
return {
|
159
|
+
message: () => `expected "${workflow.name || 'Workflow'}" to have ran provided commands, but it did not\n\nCommands have discrepancies:\n\n${commandsToPrint}`,
|
160
|
+
pass
|
161
|
+
};
|
162
|
+
}
|
163
|
+
}
|
122
164
|
globals_1.expect.extend({
|
123
|
-
toHaveFinishWithStatus,
|
124
165
|
toHaveBeenBuildAndRun,
|
125
|
-
toHaveBeenBuildAndRunWithVariables
|
166
|
+
toHaveBeenBuildAndRunWithVariables,
|
167
|
+
toHaveFinishWithStatus,
|
168
|
+
toHaveRanCommands
|
126
169
|
});
|
127
170
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,2CAAsC;AACtC,iEAA4D;AAC5D,6DAAkF;AAClF,oDAAiC;AAEjC,qBAAkB;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,2CAAsC;AACtC,iEAA4D;AAC5D,6DAAkF;AAClF,oDAAiC;AAEjC,qBAAkB;AAGlB,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,KAAK;IACb,kBAAkB,EAAE,EAAE;CACvB,CAAA;AAED,MAAM,CAAC,aAAa,GAAG;IACrB,GAAG,EAAE,KAAK,EAAE,IAAY,EAAE,OAAQ,EAAqB,EAAE;QACvD,IAAI,OAAO,EAAE,iBAAiB,EAAE;YAC9B,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAA;YAErC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACjD,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;gBACpD,MAAM,YAAY,GAAG,uBAAuB,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBAC/D,MAAM,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;gBACrC,MAAM,UAAU,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I,EAAE;gBAClC,gBAAgB,EAAE,mBAAmB,CAAC,gBAAgB;aACvD,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAA;QAEnF,OAAO;YACL,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,QAAQ,CAAC,IAAI,IAAI,UAAU,sFAAsF,eAAe,EAAE;YAC9J,IAAI;SACL,CAAA;KACF;AACH,CAAC;AAED,gBAAM,CAAC,MAAM,CAAC;IACZ,qBAAqB;IACrB,kCAAkC;IAClC,sBAAsB;IACtB,iBAAiB;CAClB,CAAC,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@universal-packages/workflows-jest",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.0",
|
4
4
|
"description": "Jest matchers for universal workflows",
|
5
5
|
"author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)",
|
6
6
|
"license": "MIT",
|