vitest-plugin-vis 2.4.1 → 2.4.2

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.
@@ -3,7 +3,7 @@ export declare const visContext: {
3
3
  __test__getOptions(projectName: string): import("../config.ts").VisOptions<any> | undefined;
4
4
  __test__reset(): void;
5
5
  __test__getState(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("./vis_context.types.ts").VisProjectState>;
6
- setupSuite(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").VisProjectState, "subjectDataTestId">>;
6
+ setupSuite(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").VisProjectState, "subjectDataTestId">>;
7
7
  getSnapshotInfo(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, name: string, isAutoSnapshot: boolean, options?: {
8
8
  snapshotFileId?: string | undefined;
9
9
  }): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBACs3D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADl2D,CAAA"}
1
+ {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC86D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAD15D,CAAA"}
@@ -10,7 +10,7 @@ export declare function createVisContext(): {
10
10
  * Test files include vitest test files and storybook story files.
11
11
  * It needs to make sure there is no race condition between the test files.
12
12
  */
13
- setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisProjectState, "subjectDataTestId">>;
13
+ setupSuite(browserContext: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisProjectState, "subjectDataTestId">>;
14
14
  getSnapshotInfo(browserContext: PartialBrowserCommandContext, name: string, isAutoSnapshot: boolean, options?: {
15
15
  snapshotFileId?: string | undefined;
16
16
  }): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.logic.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.logic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAMpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,eAAe,EAAY,MAAM,wBAAwB,CAAA;AAErG,wBAAgB,gBAAgB;eAKnB,CAAC,SAAS,OAAO,GAAG,MAAM,eAAe,MAAM,GAAG,SAAS,YAAW,UAAU,CAAC,CAAC,CAAC;oCAG9D,MAAM;;8BAOZ,4BAA4B;IAGtD;;;;OAIG;wBACuB,4BAA4B;oCAgBrC,4BAA4B,QACtC,MAAM,kBACI,OAAO,YACb;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA+Bf,4BAA4B,UAAU,MAAM;qCAI9D,4BAA4B,UACpC,MAAM,kBACE,MAAM,GAAG,SAAS,kBAClB,OAAO;wCAaP,4BAA4B,QACtC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBACjC,MAAM,GAAG,SAAS,kBAClB,OAAO;iCAWW,4BAA4B,UAAU,MAAM;;;;;;;;;;;EAmBhF;AAyBD,wBAAgB,WAAW,CAC1B,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC;;;;;;;;EAYrD;AAED,wBAAgB,UAAU,CACzB,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAGrD"}
1
+ {"version":3,"file":"vis_context.logic.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.logic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAMpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,eAAe,EAAY,MAAM,wBAAwB,CAAA;AAErG,wBAAgB,gBAAgB;eAKnB,CAAC,SAAS,OAAO,GAAG,MAAM,eAAe,MAAM,GAAG,SAAS,YAAW,UAAU,CAAC,CAAC,CAAC;oCAG9D,MAAM;;8BAOZ,4BAA4B;IAGtD;;;;OAIG;+BAC8B,4BAA4B;oCAiB5C,4BAA4B,QACtC,MAAM,kBACI,OAAO,YACb;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA+Bf,4BAA4B,UAAU,MAAM;qCAI9D,4BAA4B,UACpC,MAAM,kBACE,MAAM,GAAG,SAAS,kBAClB,OAAO;wCAaP,4BAA4B,QACtC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBACjC,MAAM,GAAG,SAAS,kBAClB,OAAO;iCAWW,4BAA4B,UAAU,MAAM;;;;;;;;;;;EAmBhF;AAyBD,wBAAgB,WAAW,CAC1B,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC;;;;;;;;EAYrD;AAED,wBAAgB,UAAU,CACzB,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAGrD"}
@@ -27,13 +27,14 @@ export function createVisContext() {
27
27
  * Test files include vitest test files and storybook story files.
28
28
  * It needs to make sure there is no race condition between the test files.
29
29
  */
30
- async setupSuite(context) {
31
- const projectId = getProjectId(context);
30
+ async setupSuite(browserContext) {
31
+ const projectId = getProjectId(browserContext);
32
+ const visOptions = getVisOptions(visOptionsRecord, browserContext);
32
33
  if (!state[projectId]) {
33
- state[projectId] = setupState(context, getVisOptions(visOptionsRecord, context) ?? {});
34
+ state[projectId] = setupState(browserContext, visOptions);
34
35
  }
35
36
  const projectState = await state[projectId];
36
- const { suiteId, suite } = createSuite(projectState, context.testPath, visOptionsRecord);
37
+ const { suiteId, suite } = createSuite(projectState, browserContext.testPath, visOptions);
37
38
  projectState.suites[suiteId] = suite;
38
39
  await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)]);
39
40
  return pick(projectState, 'subjectDataTestId');
@@ -73,7 +74,8 @@ export function createVisContext() {
73
74
  async getSuiteInfo(browserContext, taskId) {
74
75
  const projectId = getProjectId(browserContext);
75
76
  const projectState = await state[projectId];
76
- const suiteId = getSuiteId(projectState, browserContext.testPath, visOptionsRecord);
77
+ const visOptions = getVisOptions(visOptionsRecord, browserContext);
78
+ const suiteId = getSuiteId(projectState, browserContext.testPath, visOptions);
77
79
  const suite = projectState.suites[suiteId];
78
80
  const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 });
79
81
  return {
@@ -123,7 +125,7 @@ export function getSuiteId(state, testPath, options) {
123
125
  return getSnapshotSubpath(relative(state.projectRoot, testPath), options);
124
126
  }
125
127
  function getVisOptions(visOptionsRecord, context) {
126
- return visOptionsRecord[getProjectName(context) ?? '__default'];
128
+ return visOptionsRecord[getProjectName(context) ?? '__default'] ?? {};
127
129
  }
128
130
  function getProjectRoot(context) {
129
131
  return context.project.config.root;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -31,16 +31,17 @@ export function createVisContext() {
31
31
  * Test files include vitest test files and storybook story files.
32
32
  * It needs to make sure there is no race condition between the test files.
33
33
  */
34
- async setupSuite(context: PartialBrowserCommandContext) {
35
- const projectId = getProjectId(context)
34
+ async setupSuite(browserContext: PartialBrowserCommandContext) {
35
+ const projectId = getProjectId(browserContext)
36
36
 
37
+ const visOptions = getVisOptions(visOptionsRecord, browserContext)
37
38
  if (!state[projectId]) {
38
- state[projectId] = setupState(context, getVisOptions(visOptionsRecord, context) ?? {})
39
+ state[projectId] = setupState(browserContext, visOptions)
39
40
  }
40
41
 
41
42
  const projectState = await state[projectId]
42
43
 
43
- const { suiteId, suite } = createSuite(projectState, context.testPath, visOptionsRecord)
44
+ const { suiteId, suite } = createSuite(projectState, browserContext.testPath, visOptions)
44
45
  projectState.suites[suiteId] = suite
45
46
 
46
47
  await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)])
@@ -118,8 +119,8 @@ export function createVisContext() {
118
119
  async getSuiteInfo(browserContext: PartialBrowserCommandContext, taskId: string) {
119
120
  const projectId = getProjectId(browserContext)
120
121
  const projectState = await state[projectId]!
121
-
122
- const suiteId = getSuiteId(projectState, browserContext.testPath, visOptionsRecord)
122
+ const visOptions = getVisOptions(visOptionsRecord, browserContext)
123
+ const suiteId = getSuiteId(projectState, browserContext.testPath, visOptions)
123
124
  const suite = projectState.suites[suiteId]!
124
125
  const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 })
125
126
  return {
@@ -185,7 +186,7 @@ export function getSuiteId(
185
186
  }
186
187
 
187
188
  function getVisOptions(visOptionsRecord: Record<string, VisOptions<any>>, context: PartialBrowserCommandContext) {
188
- return visOptionsRecord[getProjectName(context) ?? '__default']!
189
+ return visOptionsRecord[getProjectName(context) ?? '__default'] ?? {}
189
190
  }
190
191
 
191
192
  function getProjectRoot(context: PartialBrowserCommandContext) {