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

chore: migrate to vitest #181

Merged
merged 63 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
517be7b
started test driving data collector util
cgdibble Nov 17, 2023
0abf2a7
add tests and todos, break fns down a bit
cgdibble Nov 18, 2023
34ccd91
add fraudnet util
siddy2181 Nov 27, 2023
35ece8c
update correct fn url
siddy2181 Nov 27, 2023
ed88230
cleanup
siddy2181 Nov 27, 2023
f2f3298
outline of fraudnet work
cgdibble Dec 5, 2023
5ff70ae
ohhhh boy, its messy vitest/flow stuff
cgdibble Dec 5, 2023
ef51cef
more test crazyiness
cgdibble Dec 5, 2023
377169f
moving server tests and client api to vitest WIP
cgdibble Dec 9, 2023
aa38a9e
lots of tests, lots of inprogress
cgdibble Dec 11, 2023
4bf74bb
graphql tests updated
cgdibble Dec 11, 2023
dcd3c59
lots more tests and such, evaluating the meta things cause ugh
cgdibble Dec 12, 2023
581af1f
in prgoress but coming along a ton...merge script and scriptutils tests
cgdibble Dec 12, 2023
b2a6895
so close. a couple challenges but otherwise so much progress converti…
cgdibble Dec 13, 2023
04633ea
so many files done now to fix up some lingering problem tests
cgdibble Dec 13, 2023
fd755fc
all skipped tests addressed other than logger
cgdibble Dec 14, 2023
045ab26
remove client test index and remove msw usage for mocking request
cgdibble Dec 14, 2023
5555bae
remove console logs
cgdibble Dec 14, 2023
d4549f3
remove unused modules and comment out logger test for now
cgdibble Dec 14, 2023
cfc6a31
remove some deps
cgdibble Dec 14, 2023
a90b188
remove local env pathin domain
cgdibble Dec 14, 2023
fe08185
remove logger from vitest run while evaluate deletion
cgdibble Dec 14, 2023
b6ccceb
remove logger from vitest run while evaluate deletion
cgdibble Dec 14, 2023
bec9058
got coverage going for vitest on src files
cgdibble Dec 14, 2023
14d65c1
use single coverageupload in main flow
cgdibble Dec 14, 2023
e7c8a54
remove mocha
cgdibble Dec 14, 2023
3ee4cc8
broken for now thats ok
cgdibble Dec 15, 2023
6a9230f
start testing fraudnet
cgdibble Dec 15, 2023
ecd7408
Merge branch 'main' into fraudnet-vitest
cgdibble Dec 15, 2023
145f068
add tests for fraudnet
cgdibble Dec 15, 2023
518c1e4
spy on logger, handle test for suppressing of all errors
cgdibble Dec 29, 2023
19baea9
Merge branch 'main' into fraudnet-vitest
cgdibble Dec 29, 2023
b8d458c
clear all gql mocks
cgdibble Dec 29, 2023
34d4a75
removed unneeded files, scriptUtils now all in script.test.js
cgdibble Dec 29, 2023
a36cb9f
Update src/fraudnet.js
cgdibble Dec 29, 2023
5442e78
remove unused vars/imports
cgdibble Dec 29, 2023
2895cba
remove iteration from single case test
cgdibble Dec 29, 2023
7d9e9dc
remove test index, iterate over globals for vitest setup
cgdibble Dec 29, 2023
59c195a
make envs a fn for clarity
cgdibble Dec 29, 2023
7942f40
clean up vite config file
cgdibble Dec 29, 2023
6208a31
so much flow ignore bruh
cgdibble Dec 29, 2023
07c32de
nock out some of the lint issues, but not all
cgdibble Dec 29, 2023
26c0f53
resotre logger domain local block
cgdibble Jan 5, 2024
798ce7e
fix api test
cgdibble Jan 5, 2024
9dac8bd
forgot to import host and protocol fns
cgdibble Jan 5, 2024
f581829
colocate test files and impl, remove test globals file as not needed
cgdibble Jan 5, 2024
7de6f31
put test file back since it's used in other repos
cgdibble Jan 5, 2024
32978f5
fix globals ref in webpack config
cgdibble Jan 5, 2024
e2952a4
remove sticky session id use because flow
cgdibble Jan 5, 2024
d42b0f2
remove test ref from lint step
cgdibble Jan 6, 2024
c5f79dd
fix lint errors
cgdibble Jan 6, 2024
ec428a4
fix flow again
cgdibble Jan 6, 2024
c763650
put make mock element function in helper and adjust to always pass mo…
cgdibble Jan 6, 2024
83ec9da
fix test lint imports
cgdibble Jan 8, 2024
7bcaf76
add input type for makemockscript
cgdibble Jan 8, 2024
321921a
add test back as an export
cgdibble Jan 9, 2024
fa5970b
update old coverage ignore lines to work with vitest v8
cgdibble Jan 22, 2024
d044ebc
move globals vars to own file for webpack and vitest usage
cgdibble Jan 22, 2024
b87b37a
fix webpack build and ignore hermes flow types
cgdibble Jan 22, 2024
2db61f4
add back in stickysession once belter updated
cgdibble Jan 23, 2024
72b3aee
test stickysessionid fix
cgdibble Jan 23, 2024
e04ec57
remove old codeblock comment
cgdibble Jan 23, 2024
649ea90
sort input
cgdibble Jan 23, 2024
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
11 changes: 2 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ jobs:
- name: ▶️ Run build script
run: npm run build

- name: ⬆️ Upload client coverage report
- name: ⬆️ Upload coverage report
uses: codecov/codecov-action@v3
with:
directory: ./coverage/karma
flags: client

- name: ⬆️ Upload server coverage report
uses: codecov/codecov-action@v3
with:
directory: ./coverage/jest
flags: server
directory: ./coverage
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"],
};
25 changes: 0 additions & 25 deletions karma.conf.js

This file was deleted.

21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"doc": "esdoc",
"flow": "flow",
"flow-typed": "rm -rf ./flow-typed && flow-typed install",
"karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start",
"lint": "eslint src/ server/ test/ *.js",
"lint": "eslint src/ server/ *.js",
"reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install",
"release": "./publish.sh",
"release:major": "./publish.sh major",
Expand All @@ -21,9 +20,10 @@
"setup": "npm install && npm run flow-typed",
"format": "prettier --write --ignore-unknown .",
"format:check": "prettier --check .",
"test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run jest && npm run karma",
"test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run test:unit",
"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",
"test:unit:watch": "vitest",
"test:unit": "vitest run --coverage",
cgdibble marked this conversation as resolved.
Show resolved Hide resolved
"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,8 +62,10 @@
"bowser": "^2.0.0"
},
"devDependencies": {
"@bunchtogether/vite-plugin-flow": "^1.0.2",
"@krakenjs/babel-config-grumbler": "^8.1.1",
"@krakenjs/eslint-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",
"cheerio": "1.0.0-rc.9",
"cross-env": "^7.0.3",
Expand All @@ -73,10 +75,13 @@
"flow-bin": "0.155.0",
"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-v8": "^1.0.0",
"@vitest/ui": "^1.0.0",
"vite": "^4.0.1",
"vitest": "^1.0.0"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
Expand Down
3 changes: 2 additions & 1 deletion server/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"],
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* @flow */

import cheerio from "cheerio";
import { test } from "vitest";

import { unpackSDKMeta } from "../../server";
import { unpackSDKMeta } from ".";

/**
* List with real URL query parameters.
Expand Down
3 changes: 2 additions & 1 deletion test/server/meta.test.js → server/meta.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
/* eslint max-lines: off */

import cheerio from "cheerio";
import { test, afterEach } from "vitest";

import { unpackSDKMeta } from "../../server";
import { unpackSDKMeta } from ".";

afterEach(() => {
// eslint-disable-next-line no-process-env
Expand Down
150 changes: 150 additions & 0 deletions src/api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/* @flow */
import { describe, beforeEach, it, expect, vi } from "vitest";
import { getCurrentScript, request, memoize } from "@krakenjs/belter/src";

import { createAccessToken, createOrder } from "./api";

vi.mock("@krakenjs/belter/src", async () => {
const actual = await vi.importActual("@krakenjs/belter/src");
return {
...actual,
getCurrentScript: vi.fn(),
request: vi.fn().mockResolvedValue(),
};
});

describe("api cases", () => {
let order;
const invalidClientId = "invalid-client-id";
const emptyResponseClientId = "empty-response-client-id";
const createOrderValidId = "create-order-valid-order-id";
const expectedToken =
"A21AAKNZBaqilFBC4dVVz-tr-ySIT78NREeBidy3lkGdr-EA8wbhGrByPayhgnJRPE5xg4QW46moDbCFjZ13i1GH-Ax4SjtjA";
const defaultAuthResponse = {
scope: "https://uri.paypal.com/services/invoicing",
access_token: expectedToken,
token_type: "Bearer",
app_id: "APP-80W284485P519543T",
expires_in: 31838,
nonce: "2022-03-07T22:41:38ZqHkiC0_odfzFwo27_X0wVuF67STYq39KRplBeeyY2bk",
error: null,
};

beforeEach(() => {
memoize.clear();
window.__PAYPAL_DOMAIN__ = "testurl";
// $FlowIgnore
getCurrentScript.mockReturnValue({
src: `https://sdkplz.com/sdk/js?intent=capture`,
attributes: [],
});
vi.clearAllMocks();

order = {
intent: "CAPTURE",
purchase_units: [
{
amount: {
value: "10.00",
currency_code: "USD",
},
},
],
};
});

describe("createAccessToken()", () => {
it("createAccessToken should return a valid token", async () => {
// $FlowIgnore
request.mockResolvedValueOnce({ body: defaultAuthResponse });

const result = await createAccessToken("testClient");

expect(result).toEqual(expectedToken);
});

it("createAccessToken should throw invalid client argument error", async () => {
// $FlowIgnore
request.mockResolvedValueOnce({ body: { error: "invalid_client" } });

await expect(() =>
createAccessToken(invalidClientId)
).rejects.toThrowError(/Auth Api invalid client id:/);
});

it("createAccessToken should return an error message when response is an empty object", async () => {
// $FlowIgnore
request.mockResolvedValueOnce({ body: {} });

await expect(() =>
createAccessToken(emptyResponseClientId)
).rejects.toThrow(/Auth Api response error:/);
});
});

describe("createOrder()", () => {
it("createOrder should throw an error when clientId is null", () => {
// $FlowIgnore
expect(() => createOrder(null)).toThrowError(/Client ID not passed/);
});

it("createOrder should throw an error when order is null", () => {
// $FlowIgnore
expect(() => createOrder("testClient", null)).toThrow(
/Expected order details to be passed/
);
});

it("createOrder should throw an error when order intent does not match with query parameters intent", () => {
const expectedErrorMessage =
"Unexpected intent: AUTHORIZE passed to order.create. Please ensure you are passing /sdk/js?intent=authorize in the paypal script tag.";

order.intent = "AUTHORIZE";

expect(() => createOrder("testClient", order)).toThrowError(
expectedErrorMessage
);
});

it("createOrder should throw an error when order currency does not match with query parameters currency", () => {
const expectedErrorMessage =
"Unexpected currency: AUD passed to order.create. Please ensure you are passing /sdk/js?currency=AUD in the paypal script tag.";
order.purchase_units[0].amount.currency_code = "AUD";

expect(() => createOrder("testClient", order)).toThrow(
expectedErrorMessage
);
});

it("createOrder should throw an error when order identifier is not in the server response", async () => {
const expectedErrorMessage = "Order Api response error:";
const failuredPayload = {};

request
// $FlowIgnore
.mockResolvedValueOnce({ body: defaultAuthResponse })
.mockResolvedValueOnce({ body: failuredPayload });

await expect(() => createOrder("testClient", order)).rejects.toThrow(
expectedErrorMessage
);
});

it("createOrder should return a valid orderId", async () => {
const expectedOrderId = "9BL31648CM342010L";
const mockOrderResponse = {
id: expectedOrderId,
status: "CREATED",
links: [],
};

request
// $FlowIgnore
.mockResolvedValueOnce({ body: defaultAuthResponse })
.mockResolvedValueOnce({ body: mockOrderResponse });

const result = await createOrder(createOrderValidId, order);
expect(result).toEqual(expectedOrderId);
});
});
});
39 changes: 39 additions & 0 deletions src/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* @flow */
import { describe, it, expect } from "vitest";

import {
getPayPalLoggerDomain,
buildPayPalUrl,
buildPayPalAPIUrl,
getPayPalLoggerUrl,
} from "./domains";

describe(`config cases`, () => {
it("should successfully get the global paypal logger domain", () => {
const expectedDomain = "mock://www.paypal.com";
window.__PAYPAL_DOMAIN__ = expectedDomain;
const domain = getPayPalLoggerDomain();
expect(domain).toEqual(expectedDomain);
});

it("should successfully build a paypal url", () => {
const expectedPayPalUrl = `${window.location.protocol}//${window.location.host}/foo/bar`;
const result = buildPayPalUrl("/foo/bar");

expect(result).toEqual(expectedPayPalUrl);
});

it("should successfully build a paypal api url", () => {
const expectedPayPalUrl = `${window.location.protocol}//${window.location.host}/bar/baz`;
const result = buildPayPalAPIUrl("/bar/baz");

expect(result).toEqual(expectedPayPalUrl);
});

it("should successfully build a paypal logger url", () => {
const expectedPayPalUrl = `${window.location.protocol}//${window.location.host}/xoplatform/logger/api/logger`;
const result = getPayPalLoggerUrl();

expect(result).toEqual(expectedPayPalUrl);
});
});
4 changes: 2 additions & 2 deletions src/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
} from "@krakenjs/cross-domain-utils/src";

import {
getProtocol,
getStageHost,
getPayPalDomain,
getPayPalAPIDomain,
getStageHost,
cgdibble marked this conversation as resolved.
Show resolved Hide resolved
getProtocol,
} from "./global";
import { URI } from "./config";

Expand Down
Loading
Loading