From 5ff70aef6ae2a3d20ce2844e82a4d5627ebf5efa Mon Sep 17 00:00:00 2001 From: cdibble Date: Mon, 4 Dec 2023 16:56:57 -0800 Subject: [PATCH] ohhhh boy, its messy vitest/flow stuff --- babel.config.js | 3 +- jest.config.js | 1 + package.json | 12 ++++- test/client/{api.js => api.test.js} | 0 test/client/fraudnet.js | 21 ++++++++ test/client/index.js | 25 +++++----- test/client/{tracking.js => tracking.test.js} | 1 + vite.config.js | 49 +++++++++++++++++++ webpack.config.js | 8 +-- 9 files changed, 100 insertions(+), 20 deletions(-) rename test/client/{api.js => api.test.js} (100%) create mode 100644 test/client/fraudnet.js rename test/client/{tracking.js => tracking.test.js} (96%) create mode 100644 vite.config.js diff --git a/babel.config.js b/babel.config.js index 66bc35cb..86eb1e46 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,5 +2,6 @@ /* eslint import/no-commonjs: off */ module.exports = { - extends: "@krakenjs/babel-config-grumbler/babelrc-node", + extends: "@krakenjs/grumbler-scripts/config/.babelrc-node", + presets: ["@krakenjs/babel-config-grumbler/flow-ts-babel-preset"], }; diff --git a/jest.config.js b/jest.config.js index 252d7327..1d55fbb4 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,4 +3,5 @@ module.exports = { testEnvironment: "jsdom", + transformIgnorePatterns: ["node_modules/(?!@krakenjs|(?!deck.gl))"], }; diff --git a/package.json b/package.json index 3733efc5..d78cce74 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run jest && npm run karma", "webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress", "jest": "jest test/server --env=node --no-cache --collectCoverageFrom='server/' --coverageDirectory='coverage/jest' --coverage --verbose --runInBand --silent=false", + "vitest": "vitest run", "prepublishOnly": "npm run babel", "postpublish": "rm -rf ./server && git checkout ./server", "validate-codecov": "curl --data-binary @.github/codecov.yml https://codecov.io/validate", @@ -62,6 +63,9 @@ "bowser": "^2.0.0" }, "devDependencies": { + "@krakenjs/babel-config-grumbler": "^8.1.1", + "@krakenjs/eslint-config-grumbler": "^8.1.1", + "@krakenjs/webpack-config-grumbler": "^8.1.1", "@krakenjs/grumbler-scripts": "^8.0.4", "@krakenjs/sync-browser-mocks": "^3.0.0", "babel-core": "7.0.0-bridge.0", @@ -74,9 +78,15 @@ "flow-typed": "^3.8.0", "husky": "^8.0.1", "jest": "^29.3.1", + "jsdom": "^20.0.3", "lint-staged": "^13.0.3", "mocha": "^10.0.0", - "prettier": "2.8.8" + "prettier": "2.8.8", + "@vitest/coverage-c8": "^0.25.8", + "@vitest/ui": "^0.25.8", + "msw": "^0.49.2", + "vite": "^4.0.1", + "vitest": "^0.25.8" }, "lint-staged": { "**/*": "prettier --write --ignore-unknown" diff --git a/test/client/api.js b/test/client/api.test.js similarity index 100% rename from test/client/api.js rename to test/client/api.test.js diff --git a/test/client/fraudnet.js b/test/client/fraudnet.js new file mode 100644 index 00000000..d63b4f86 --- /dev/null +++ b/test/client/fraudnet.js @@ -0,0 +1,21 @@ +/* @flow */ +import { loadFraudnet } from "../../src/fraudnet"; + +describe("fraudnet.js", () => { + describe("loadFraudnet()", () => { + const fraudnetInputs = { + env: "test", + clientMetadataID: "test-cmid", + cspNonce: "test-csp-nonce", + timeout: 100, + appName: "sdk-test", + queryStringParams: {}, + }; + + it("creates both scripts", async () => { + loadFraudnet(fraudnetInputs); + + expect(document.createElement).toBeCalledWith("script"); + }); + }); +}); diff --git a/test/client/index.js b/test/client/index.js index 3d5ba288..6de489f6 100644 --- a/test/client/index.js +++ b/test/client/index.js @@ -1,14 +1,15 @@ /* @flow */ -import "./common"; -import "./meta"; -import "./script"; -import "./scriptUtils"; -import "./config"; -import "./global"; -import "./logger"; -import "./domains"; -import "./session"; -import "./api"; -import "./tracking"; -import "./graphql"; +// import "./common"; +// import "./meta"; +// import "./script"; +// import "./scriptUtils"; +// import "./config"; +// import "./global"; +// import "./logger"; +// import "./domains"; +import "./fraudnet"; +// import "./session"; +// import "./api"; +// import "./tracking"; +// import "./graphql"; diff --git a/test/client/tracking.js b/test/client/tracking.test.js similarity index 96% rename from test/client/tracking.js rename to test/client/tracking.test.js index 76a517aa..1bc38d8b 100644 --- a/test/client/tracking.js +++ b/test/client/tracking.test.js @@ -1,4 +1,5 @@ /* @flow */ +import { describe, it } from "vitest"; import { getSDKInitTime, setupLogger } from "../../src/tracking"; diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 00000000..6dcf5401 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,49 @@ +/* eslint-disable spaced-comment */ +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// + +// Configure Vitest (https://vitest.dev/config/) + +import path from "path"; + +import { defineConfig } from "vite"; + +const define = { + __DEBUG__: false, + __TEST__: true, + __WEB__: true, + + // __PORT__: 8000, + // __STAGE_HOST__: "msmaster.qa.paypal.com", + // __HOST__: "test.paypal.com", + // __HOSTNAME__: "test.paypal.com", + __SDK_HOST__: true, + __PATH__: true, + + // __VERSION__: "1.0.45", + // __CORRELATION_ID__: "abc123", + // __NAMESPACE__: "paypaltest", + __PAYPAL_DOMAIN__: true, + __PAYPAL_API_DOMAIN__: true, + + __POST_ROBOT__: JSON.stringify({ + __GLOBAL_KEY__: `__post_robot__`, + __AUTO_SETUP__: false, + __IE_POPUP_SUPPORT__: false, + __GLOBAL_MESSAGE_SUPPORT__: true, + __SCRIPT_NAMESPACE__: false, + }), + __PAYPAL_CHECKOUT__: JSON.stringify({ + _MAJOR_VERSION__: "", + __MINOR_VERSION__: "", + }), + // ...sdkClientTestGlobals, +}; + +// eslint-disable-next-line import/no-default-export +export default defineConfig({ + define, + test: { + environment: "jsdom", + }, +}); diff --git a/webpack.config.js b/webpack.config.js index e2276b58..adf9a7de 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,8 +1,7 @@ /* @flow */ /* eslint import/no-nodejs-modules: off */ - -import type { WebpackConfig } from "@krakenjs/webpack-config-grumbler/index.flow"; -import { getWebpackConfig } from "@krakenjs/webpack-config-grumbler"; +import type { WebpackConfig } from "@krakenjs/grumbler-scripts/config/types"; +import { getWebpackConfig } from "@krakenjs/grumbler-scripts/config/webpack.config"; import { sdkClientTestGlobals } from "./test/globals"; @@ -12,6 +11,3 @@ export const WEBPACK_CONFIG_TEST: WebpackConfig = getWebpackConfig({ ...sdkClientTestGlobals, }, }); - -// eslint-disable-next-line import/no-default-export -export default [WEBPACK_CONFIG_TEST];