Skip to content

Commit

Permalink
ohhhh boy, its messy vitest/flow stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
cgdibble committed Dec 5, 2023
1 parent f2f3298 commit 5ff70ae
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 20 deletions.
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
};
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

module.exports = {
testEnvironment: "jsdom",
transformIgnorePatterns: ["node_modules/(?!@krakenjs|(?!deck.gl))"],
};
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions test/client/fraudnet.js
Original file line number Diff line number Diff line change
@@ -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 () => {

Check failure on line 15 in test/client/fraudnet.js

View workflow job for this annotation

GitHub Actions / main

Async arrow function has no 'await' expression
loadFraudnet(fraudnetInputs);

expect(document.createElement).toBeCalledWith("script");

Check failure on line 18 in test/client/fraudnet.js

View workflow job for this annotation

GitHub Actions / main

'expect' is not defined
});
});
});
25 changes: 13 additions & 12 deletions test/client/index.js
Original file line number Diff line number Diff line change
@@ -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";
1 change: 1 addition & 0 deletions test/client/tracking.js → test/client/tracking.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* @flow */
import { describe, it } from "vitest";

import { getSDKInitTime, setupLogger } from "../../src/tracking";

Expand Down
49 changes: 49 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable spaced-comment */

Check failure on line 1 in vite.config.js

View workflow job for this annotation

GitHub Actions / main

Requires 'eslint-enable' directive for 'spaced-comment'
// eslint-disable-next-line @typescript-eslint/triple-slash-reference

Check failure on line 2 in vite.config.js

View workflow job for this annotation

GitHub Actions / main

Definition for rule '@typescript-eslint/triple-slash-reference' was not found
/// <reference types="vitest" />

// Configure Vitest (https://vitest.dev/config/)

import path from "path";

Check failure on line 7 in vite.config.js

View workflow job for this annotation

GitHub Actions / main

Flow file annotation is missing

Check failure on line 7 in vite.config.js

View workflow job for this annotation

GitHub Actions / main

Do not import Node.js builtin module "path"

Check failure on line 7 in vite.config.js

View workflow job for this annotation

GitHub Actions / main

'path' is defined but never used

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",
},
});
8 changes: 2 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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];

0 comments on commit 5ff70ae

Please sign in to comment.