Skip to content

Commit

Permalink
[Storybook] Correct passing global setup variables (#136)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan Graham <[email protected]>
  • Loading branch information
omacranger and Logan Graham authored Sep 12, 2024
1 parent 69838f7 commit 40cf18e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
6 changes: 6 additions & 0 deletions visual-js/.changeset/dry-timers-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@saucelabs/visual-playwright": patch
"@saucelabs/visual-storybook": patch
---

Correct passing options to global setup
10 changes: 9 additions & 1 deletion visual-js/visual-playwright/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,21 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
});
}

public async setup(opts?: VisualEnvOpts) {
/**
* Method to parse ENVs and bootstrap settings for the runners -- executed once globally.
*/
public globalSetup<T extends VisualEnvOpts>(opts?: Partial<T>) {
parseOpts();

if (opts) {
setOpts(opts);
}
}

/**
* Method to instantiate and create a build if not present during worker setup.
*/
public async setup() {
await downloadDomScript(this.api);

const { buildId: passedBuildId, customId } = getOpts();
Expand Down
6 changes: 5 additions & 1 deletion visual-js/visual-playwright/src/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import VisualPlaywright from './api';
import type { Page } from 'playwright-core';
import { TestInfo } from '@playwright/test';
import { SauceVisualParams } from './types';
import { VisualEnvOpts } from '@saucelabs/visual';

export const sauceVisualSetup = VisualPlaywright.setup.bind(VisualPlaywright);
export const sauceVisualSetup = async (opts?: Partial<VisualEnvOpts>) => {
VisualPlaywright.globalSetup(opts);
return VisualPlaywright.setup();
};
export const sauceVisualTeardown =
VisualPlaywright.teardown.bind(VisualPlaywright);
export const sauceVisualCheck = async (
Expand Down
11 changes: 2 additions & 9 deletions visual-js/visual-storybook/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import type { Config } from '@jest/types';
import { internals } from '@saucelabs/visual-playwright';
import { VisualOpts } from './types';

const { setOpts, parseOpts } = internals;
import { VisualStorybook } from './api';

export const getVisualTestConfig = (
opts?: Partial<VisualOpts>,
): Partial<Config.InitialOptions> => {
parseOpts();

if (opts) {
setOpts(opts);
}

VisualStorybook.globalSetup(opts);
return {
globalSetup: require.resolve(
'@saucelabs/visual-storybook/build/config/global-setup.js',
Expand Down
10 changes: 5 additions & 5 deletions visual-js/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3577,13 +3577,13 @@ __metadata:
languageName: unknown
linkType: soft

"@saucelabs/visual-playwright@^0.1.0, @saucelabs/visual-playwright@workspace:visual-playwright":
"@saucelabs/visual-playwright@^0.1.1, @saucelabs/visual-playwright@workspace:visual-playwright":
version: 0.0.0-use.local
resolution: "@saucelabs/visual-playwright@workspace:visual-playwright"
dependencies:
"@jest/globals": ^28.0.0 || ^29.0.0
"@playwright/test": ^1.42.1
"@saucelabs/visual": ^0.8.1
"@saucelabs/visual": ^0.8.2
"@storybook/types": ^8.0.2
"@tsconfig/node18": ^2.0.0
"@types/node": ^18.13.0
Expand Down Expand Up @@ -3612,8 +3612,8 @@ __metadata:
resolution: "@saucelabs/visual-storybook@workspace:visual-storybook"
dependencies:
"@jest/globals": ^28.0.0 || ^29.0.0
"@saucelabs/visual": ^0.8.0
"@saucelabs/visual-playwright": ^0.1.0
"@saucelabs/visual": ^0.8.2
"@saucelabs/visual-playwright": ^0.1.1
"@storybook/test-runner": ">=0.13.0"
"@storybook/types": ^8.0.2
"@tsconfig/node18": ^2.0.0
Expand Down Expand Up @@ -3642,7 +3642,7 @@ __metadata:
languageName: unknown
linkType: soft

"@saucelabs/visual@^0.8.0, @saucelabs/visual@^0.8.1, @saucelabs/visual@workspace:visual":
"@saucelabs/visual@^0.8.0, @saucelabs/visual@^0.8.2, @saucelabs/visual@workspace:visual":
version: 0.0.0-use.local
resolution: "@saucelabs/visual@workspace:visual"
dependencies:
Expand Down

0 comments on commit 40cf18e

Please sign in to comment.