Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1055 from Shopify/ml-graphql-client-testing-serve…
Browse files Browse the repository at this point in the history
…r-env

[GraphQL Client] Enable server and browser testing in graphql-client package
melissaluu authored Nov 13, 2023
2 parents 6c2274a + 3e0f6bb commit 4fe9ebf
Showing 14 changed files with 174 additions and 184 deletions.
2 changes: 2 additions & 0 deletions .changeset/breezy-hotels-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
29 changes: 22 additions & 7 deletions packages/graphql-client/package.json
Original file line number Diff line number Diff line change
@@ -41,7 +41,27 @@
"release": "yarn build && changeset publish"
},
"jest": {
"testEnvironment": "jsdom",
"projects": [
{
"displayName": {
"name": "test:browser",
"color": "blue"
},
"testEnvironment": "jsdom",
"testPathIgnorePatterns": [
"(/__tests__/.*|(\\.|/)server(\\.|/)(test|spec))\\.[jt]sx?$"
]
},
{
"displayName": {
"name": "test:server",
"color": "yellow"
},
"testPathIgnorePatterns": [
"(/__tests__/.*|(\\.|/)browser(\\.|/)(test|spec))\\.[jt]sx?$"
]
}
],
"setupFilesAfterEnv": [
"./src/tests/setupTests.ts"
],
@@ -60,12 +80,7 @@
"Storefront API"
],
"files": [
"**/*.d.ts",
"**/*.d.ts.map",
"**/*.js",
"**/*.js.map",
"**/*.mjs",
"**/*.mjs.map",
"dist/**/*.*",
"!node_modules"
],
"dependencies": {},
6 changes: 3 additions & 3 deletions packages/graphql-client/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export function getPlugins({ tsconfig, minify } = {}) {
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig ? tsconfig : "./tsconfig.build.json",
tsconfig: tsconfig ? tsconfig : "./tsconfig.json",
outDir: "./dist/ts",
}),
...(minify === true ? [terser({ keep_fnames: new RegExp("fetch") })] : []),
@@ -36,7 +36,7 @@ const config = [
input: clientSrcInput,
plugins: getPlugins({
minify: true,
tsconfig: "./tsconfig.build.umd.json",
tsconfig: "./tsconfig.umd.json",
}),
output: [
{
@@ -51,7 +51,7 @@ const config = [
{
input: clientSrcInput,
plugins: getPlugins({
tsconfig: "./tsconfig.build.umd.json",
tsconfig: "./tsconfig.umd.json",
}),
output: [
{
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ const mockDate = new Date("2023-10-15");

describe("getCurrentApiVersion()", () => {
beforeEach(() => {
jest.spyOn(window, "Date").mockImplementation(() => mockDate);
jest.spyOn(global, "Date").mockImplementation(() => mockDate);
});

afterEach(() => {
@@ -27,7 +27,7 @@ describe("getCurrentApiVersion()", () => {

describe("getCurrentSupportedApiVersions()", () => {
beforeEach(() => {
jest.spyOn(window, "Date").mockImplementation(() => mockDate);
jest.spyOn(global, "Date").mockImplementation(() => mockDate);
});

afterEach(() => {
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ describe("validateRequiredApiVersion()", () => {

beforeEach(() => {
consoleWarnSpy = jest
.spyOn(window.console, "warn")
.spyOn(global.console, "warn")
.mockImplementation(jest.fn());
});

291 changes: 137 additions & 154 deletions packages/graphql-client/src/graphql-client/tests/graphql-client.test.ts

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions packages/graphql-client/tsconfig.build.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/graphql-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": ["./src/**/*.ts"],
"exclude": ["./node_modules"],
"exclude": ["./node_modules", "./src/**/tests/**/*.ts"],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.build.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"declarationMap": false
2 changes: 0 additions & 2 deletions packages/storefront-api-client/package.json
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@
},
"testEnvironment": "jsdom",
"testPathIgnorePatterns": [
".rollup.cache/",
"(/__tests__/.*|(\\.|/)server(\\.|/)(test|spec))\\.[jt]sx?$"
]
},
@@ -59,7 +58,6 @@
"color": "yellow"
},
"testPathIgnorePatterns": [
".rollup.cache/",
"(/__tests__/.*|(\\.|/)browser(\\.|/)(test|spec))\\.[jt]sx?$"
]
}
6 changes: 3 additions & 3 deletions packages/storefront-api-client/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export function getPlugins({ tsconfig, minify } = {}) {
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig ? tsconfig : "./tsconfig.build.json",
tsconfig: tsconfig ? tsconfig : "./tsconfig.json",
outDir: "./dist/ts",
}),
...(minify === true ? [terser({ keep_fnames: new RegExp("fetch") })] : []),
@@ -35,7 +35,7 @@ const config = [
input: mainSrcInput,
plugins: getPlugins({
minify: true,
tsconfig: "./tsconfig.build.umd.json",
tsconfig: "./tsconfig.umd.json",
}),
output: [
{
@@ -50,7 +50,7 @@ const config = [
{
input: mainSrcInput,
plugins: getPlugins({
tsconfig: "./tsconfig.build.umd.json",
tsconfig: "./tsconfig.umd.json",
}),
output: [
{
4 changes: 0 additions & 4 deletions packages/storefront-api-client/tsconfig.build.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/storefront-api-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": ["./src/**/*.ts"],
"exclude": ["./node_modules"],
"exclude": ["./node_modules", "./src/**/tests/**/*.ts"],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.build.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"declarationMap": false

0 comments on commit 4fe9ebf

Please sign in to comment.