pa11y-ci-reporter-runner 4.0.0 → 4.1.0
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/LICENSE +1 -1
- package/lib/pa11yci-machine.js +10 -9
- package/lib/pa11yci-service.js +32 -13
- package/package.json +8 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022 -
|
|
3
|
+
Copyright (c) 2022 - 2024 Aaron Goldenthal
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/lib/pa11yci-machine.js
CHANGED
|
@@ -13,10 +13,10 @@ const { createMachine, assign } = require('xstate');
|
|
|
13
13
|
*/
|
|
14
14
|
const pa11yciMachine = createMachine(
|
|
15
15
|
{
|
|
16
|
-
context: {
|
|
17
|
-
urlIndex:
|
|
18
|
-
urls:
|
|
19
|
-
},
|
|
16
|
+
context: ({ input }) => ({
|
|
17
|
+
urlIndex: input.urlIndex,
|
|
18
|
+
urls: input.urls
|
|
19
|
+
}),
|
|
20
20
|
id: 'pa11yci-runner',
|
|
21
21
|
initial: 'init',
|
|
22
22
|
// Opting in for v4, will be default in xstate v5
|
|
@@ -34,7 +34,7 @@ const pa11yciMachine = createMachine(
|
|
|
34
34
|
beforeAll: {
|
|
35
35
|
on: {
|
|
36
36
|
NEXT: [
|
|
37
|
-
{ target: 'beginUrl',
|
|
37
|
+
{ target: 'beginUrl', guard: 'hasUrls' },
|
|
38
38
|
{ target: 'afterAll' }
|
|
39
39
|
],
|
|
40
40
|
RESET: { target: 'init' }
|
|
@@ -49,7 +49,7 @@ const pa11yciMachine = createMachine(
|
|
|
49
49
|
urlResults: {
|
|
50
50
|
on: {
|
|
51
51
|
NEXT: [
|
|
52
|
-
{ target: 'afterAll',
|
|
52
|
+
{ target: 'afterAll', guard: 'isLastUrl' },
|
|
53
53
|
{ target: 'beginUrl', actions: 'incrementUrl' }
|
|
54
54
|
],
|
|
55
55
|
RESET: { target: 'init' }
|
|
@@ -66,15 +66,16 @@ const pa11yciMachine = createMachine(
|
|
|
66
66
|
{
|
|
67
67
|
actions: {
|
|
68
68
|
incrementUrl: assign({
|
|
69
|
-
urlIndex: (context) => context.urlIndex + 1
|
|
69
|
+
urlIndex: ({ context }) => context.urlIndex + 1
|
|
70
70
|
}),
|
|
71
71
|
setInitialUrlIndex: assign({
|
|
72
72
|
urlIndex: () => 0
|
|
73
73
|
})
|
|
74
74
|
},
|
|
75
75
|
guards: {
|
|
76
|
-
hasUrls: (context) => context.urls.length > 0,
|
|
77
|
-
isLastUrl: (context) =>
|
|
76
|
+
hasUrls: ({ context }) => context.urls.length > 0,
|
|
77
|
+
isLastUrl: ({ context }) =>
|
|
78
|
+
context.urlIndex === context.urls.length - 1
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
);
|
package/lib/pa11yci-service.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @module pa11yci-service
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
const { createActor, getNextSnapshot } = require('xstate');
|
|
10
11
|
const machine = require('./pa11yci-machine');
|
|
11
12
|
const RunnerStates = require('./runner-states');
|
|
12
13
|
|
|
@@ -38,6 +39,14 @@ const StateTypes = Object.freeze({
|
|
|
38
39
|
next: 'next'
|
|
39
40
|
});
|
|
40
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Generates a machine event object for the given event type.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} eventType The type of event (a MachineEvents value).
|
|
46
|
+
* @returns {object} The machine event object.
|
|
47
|
+
*/
|
|
48
|
+
const getMachineEvent = (eventType) => ({ type: eventType });
|
|
49
|
+
|
|
41
50
|
/**
|
|
42
51
|
* Gets the initial pa11yci-runner state machine context given an array of URLs.
|
|
43
52
|
*
|
|
@@ -68,6 +77,7 @@ const hasUrl = (state) =>
|
|
|
68
77
|
* @private
|
|
69
78
|
*/
|
|
70
79
|
const getUrlForState = (machineState) =>
|
|
80
|
+
// Only a subset of states have an associated URL
|
|
71
81
|
hasUrl(machineState.value)
|
|
72
82
|
? // User supplied input used to index user supplied data file
|
|
73
83
|
// nosemgrep: eslint.detect-object-injection
|
|
@@ -126,12 +136,17 @@ const getStateSummary = (machineState) => ({
|
|
|
126
136
|
const serviceFactory = (urls, actions) => {
|
|
127
137
|
let pendingCommand;
|
|
128
138
|
|
|
129
|
-
// Implement custom xstate
|
|
139
|
+
// Implement custom xstate actor, which allows for tracking for current
|
|
130
140
|
// and the next state, which is required for some control functions.
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
let
|
|
141
|
+
const pa11yActor = createActor(machine, {
|
|
142
|
+
input: getInitialContext(urls)
|
|
143
|
+
});
|
|
144
|
+
let currentState = pa11yActor.getSnapshot();
|
|
145
|
+
let nextState = getNextSnapshot(
|
|
146
|
+
machine,
|
|
147
|
+
currentState,
|
|
148
|
+
getMachineEvent(MachineEvents.NEXT)
|
|
149
|
+
);
|
|
135
150
|
|
|
136
151
|
/**
|
|
137
152
|
* Validates that a command is allowed in the given state. Throws if invalid.
|
|
@@ -167,24 +182,28 @@ const serviceFactory = (urls, actions) => {
|
|
|
167
182
|
pendingCommand = true;
|
|
168
183
|
|
|
169
184
|
// Send event to the machine and executes the action for the
|
|
170
|
-
// current state (except in init, which has no action)
|
|
171
|
-
currentState =
|
|
185
|
+
// new current state (except in init, which has no action).
|
|
186
|
+
currentState = getNextSnapshot(
|
|
187
|
+
machine,
|
|
188
|
+
currentState,
|
|
189
|
+
getMachineEvent(event)
|
|
190
|
+
);
|
|
172
191
|
if (currentState.value !== 'init') {
|
|
173
|
-
// Value is internal object state
|
|
192
|
+
// Value is internal object state.
|
|
174
193
|
// nosemgrep: eslint.detect-object-injection, unsafe-dynamic-method
|
|
175
194
|
await actions[currentState.value](getUrlForState(currentState));
|
|
176
195
|
}
|
|
177
196
|
|
|
178
|
-
// Check next state and save for reference
|
|
179
|
-
// is a pure function, so only retrieves the state)
|
|
197
|
+
// Check next state and save for reference.
|
|
180
198
|
if (currentState.value !== finalState) {
|
|
181
|
-
nextState =
|
|
199
|
+
nextState = getNextSnapshot(
|
|
200
|
+
machine,
|
|
182
201
|
currentState,
|
|
183
|
-
MachineEvents.NEXT
|
|
202
|
+
getMachineEvent(MachineEvents.NEXT)
|
|
184
203
|
);
|
|
185
204
|
}
|
|
186
205
|
} finally {
|
|
187
|
-
// Ensure pending command is reset in all cases, including on error
|
|
206
|
+
// Ensure pending command is reset in all cases, including on error.
|
|
188
207
|
pendingCommand = false;
|
|
189
208
|
}
|
|
190
209
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pa11y-ci-reporter-runner",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Pa11y CI Reporter Runner is designed to facilitate testing of Pa11y CI reporters. Given a Pa11y CI JSON results file and optional configuration it simulates the Pa11y CI calls to the reporter.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://gitlab.com/gitlab-ci-utils/pa11y-ci-reporter-runner",
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@aarongoldenthal/eslint-config-standard": "^
|
|
45
|
-
"eslint": "^8.
|
|
44
|
+
"@aarongoldenthal/eslint-config-standard": "^25.0.0",
|
|
45
|
+
"eslint": "^8.56.0",
|
|
46
46
|
"jest": "^29.7.0",
|
|
47
47
|
"jest-junit": "^16.0.0",
|
|
48
|
-
"markdownlint-cli2": "^0.
|
|
48
|
+
"markdownlint-cli2": "^0.11.0",
|
|
49
49
|
"pa11y-ci-reporter-cli-summary": "^3.0.0",
|
|
50
|
-
"prettier": "^3.
|
|
51
|
-
"tsd": "^0.
|
|
52
|
-
"typescript": "^5.
|
|
50
|
+
"prettier": "^3.1.1",
|
|
51
|
+
"tsd": "^0.30.3",
|
|
52
|
+
"typescript": "^5.3.3"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"lodash": "^4.17.21",
|
|
56
|
-
"xstate": "^
|
|
56
|
+
"xstate": "^5.5.1"
|
|
57
57
|
}
|
|
58
58
|
}
|