Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: preload all icons for chromatic screenshot tests #11267

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@octokit/webhooks-types": "7.6.1",
"@prettier/sync": "0.5.2",
"@rollup/plugin-node-resolve": "16.0.0",
"@rollup/plugin-replace": "6.0.2",
"@rollup/plugin-typescript": "12.1.2",
"@storybook/addon-a11y": "8.4.7",
"@storybook/addon-controls": "8.4.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"lint:scss": "stylelint --fix \"src/**/*.scss\" && prettier --write \"**/*.scss\" >/dev/null",
"lint:ts": "eslint --fix . && prettier --write \"**/*.{ts,tsx,cjs,mjs}\" >/dev/null",
"prepublish": "./support/cleanupDistFiles.sh",
"screenshot-tests": "npm run build-storybook",
"screenshot-tests": "npm run build-storybook --mode=dev",
"screenshot-tests:preview": "npm run util:prep-build-reqs && NODE_OPTIONS=--openssl-legacy-provider STORYBOOK_SCREENSHOT_LOCAL_BUILD=true storybook dev",
"screenshot-tests:publish": "npm run screenshot-tests && storybook-to-ghpages --existing-output-dir=docs",
"start": "npm run util:clean-js-files && concurrently --kill-others --raw \"tsc --project ./tsconfig-demos.json --watch\" \"npm run build:watch-dev\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Icon extends LitElement {
// #region Lifecycle

override connectedCallback(): void {
if (this.preload) {
if (this.preload || (import.meta.env.MODE === "development" && __STORYBOOK_SCREENSHOT_TEST_BUILD__)) {
this.visible = true;
this.loadIconPathData();
return;
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/utils/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ describe("config", () => {
});

describe("stampVersion", () => {
const calciteVersionPreBuildPlaceholder = "__CALCITE_VERSION__";
const buildVersion = __CALCITE_VERSION__;

beforeEach(() => delete globalThis.calciteConfig);

it("creates global config and stamps the version onto it", async () => {
config = await loadConfig();
config.stampVersion();
expect(globalThis.calciteConfig.version).toBe(calciteVersionPreBuildPlaceholder);
expect(globalThis.calciteConfig.version).toBe(buildVersion);
});

it("stamps the version onto existing config if there's no version present", async () => {
globalThis.calciteConfig = {};
config = await loadConfig();
config.stampVersion();
expect(globalThis.calciteConfig.version).toBe(calciteVersionPreBuildPlaceholder);
expect(globalThis.calciteConfig.version).toBe(buildVersion);
});

it("bails if version is already stamped onto existing config", async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const runningInE2ETest = import.meta.env.MODE === "test" && !isServer;
export const logLevel: LogLevel = existingConfig?.logLevel || (runningInE2ETest ? "error" : "info");

// the following placeholders are replaced by the build
const version = "__CALCITE_VERSION__";
const buildDate = "__CALCITE_BUILD_DATE__";
const revision = "__CALCITE_REVISION__";
const version = __CALCITE_VERSION__;
const buildDate = __CALCITE_BUILD_DATE__;
const revision = __CALCITE_REVISION__;

/** Stamp the version onto the global config. */
export function stampVersion(): void {
Expand Down
4 changes: 4 additions & 0 deletions packages/calcite-components/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const __CALCITE_BUILD_DATE__: string;
declare const __CALCITE_REVISION__: string;
declare const __CALCITE_VERSION__: string;
declare const __STORYBOOK_SCREENSHOT_TEST_BUILD__: boolean;
19 changes: 8 additions & 11 deletions packages/calcite-components/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import stylelint from "stylelint";
// TODO: [MIGRATION] evaluate the usages of the key={} props - most of the time key is not necessary in Lit. See https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-jsx--docs#key-prop
import { defineConfig } from "vite";
import { useLumina } from "@arcgis/lumina-compiler";
import replace from "@rollup/plugin-replace";
import { version } from "./package.json";
import tailwindConfig from "./tailwind.config";

Expand Down Expand Up @@ -53,16 +52,6 @@ export default defineConfig({
},
},
}),
process.env.NODE_ENV !== "test" &&
replace({
values: {
__CALCITE_BUILD_DATE__: () => new Date().toISOString().split("T")[0],
__CALCITE_REVISION__: execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim(),
__CALCITE_VERSION__: version,
},
include: ["src/utils/config.ts"],
preventAssignment: true,
}),
],

css: {
Expand Down Expand Up @@ -95,6 +84,14 @@ export default defineConfig({
],
},
},

define: {
__CALCITE_BUILD_DATE__: JSON.stringify(new Date().toISOString().split("T")[0]),
__CALCITE_REVISION__: JSON.stringify(execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim()),
__CALCITE_VERSION__: JSON.stringify(version),
__STORYBOOK_SCREENSHOT_TEST_BUILD__: process.env.STORYBOOK_SCREENSHOT_TEST_BUILD,
},

test: {
setupFiles: ["src/tests/setupTests.ts"],
include: ["**/*.{e2e,spec}.?(c|m)[jt]s?(x)"],
Expand Down
Loading