Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustinMauroy committed Nov 25, 2023
1 parent 8ecbcf7 commit 93887e8
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 96 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": "prettier",
"overrides": [
// @TODO: Remove this old support
{
"files": ["**/*.jest.*"],
"env": { "jest": true }
},
{
"files": ["public/**/*.js"],
"env": { "browser": true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import ThemeToggle from '../';
import ThemeToggle from '..';

let mockCurrentTheme = 'light';

Expand Down
164 changes: 89 additions & 75 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"format": "npm run lint:fix && npm run prettier:fix",
"storybook": "cross-env NODE_NO_WARNINGS=1 storybook dev -p 6006 --quiet --no-open",
"storybook:build": "cross-env NODE_NO_WARNINGS=1 storybook build --quiet --webpack-stats-json",
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --import=tsx --test **/__tests__/*.test.mjs",
"test:watch": "cross-env NODE_NO_WARNINGS=1 node --import=tsx --test --watch **/__tests__/*.test.mjs",
"test:coverage": "cross-env NODE_NO_WARNINGS=1 node --import=tsx --test --experimental-test-coverage --test-reporter=junit --test-reporter-destination=junit.xml",
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --import=tsx --test **/*.test.mjs **/*.test.jsx",
"test:watch": "cross-env NODE_NO_WARNINGS=1 node --import=tsx --test --watch **/*.test.mjs **/*.test.jsx",
"test:coverage": "cross-env NODE_NO_WARNINGS=1 node --import=tsx --test --experimental-test-coverage --test-reporter=junit --test-reporter-destination=junit.xml **/*.test.mjs **/*.test.jsx",
"test": "npm run test:unit",
"prepare": "husky install"
},
Expand All @@ -52,6 +52,7 @@
"@radix-ui/react-toast": "^1.1.5",
"@sentry/nextjs": "^7.80.1",
"@sentry/profiling-node": "^1.2.6",
"@testing-library/react": "~14.1.2",
"@types/node": "20.8.10",
"@vcarl/remark-headings": "~0.1.0",
"@vercel/analytics": "~1.1.1",
Expand Down
36 changes: 19 additions & 17 deletions scripts/lighthouse/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { formatLighthouseResults } from '..';
import { strictEqual, ok } from 'node:assert';
import { describe, it, beforeEach, afterEach, mock } from 'node:test';

import { formatLighthouseResults } from '../index.mjs';

describe('formatLighthouseResults', () => {
// WARNING: if you change this value, you must also change the value in regex below
const MOCK_VERCEL_PREVIEW_URL = `https://some.vercel.preview.url`;

const MOCK_LIGHTHOUSE_RESULT = `[
Expand All @@ -21,10 +25,10 @@ describe('formatLighthouseResults', () => {
"${MOCK_VERCEL_PREVIEW_URL}/en/download" : "fake.url/to/result/2"
}`;

let mockCore, originalEnv;
const mockCore = { setOutput: mock.fn() };
let originalEnv;

beforeEach(() => {
mockCore = { setOutput: jest.fn() };
originalEnv = process.env;
process.env = {
...process.env,
Expand All @@ -41,29 +45,27 @@ describe('formatLighthouseResults', () => {
it('formats preview urls correctly', () => {
formatLighthouseResults({ core: mockCore });

const expectations = [
expect.stringContaining(`[/en](${MOCK_VERCEL_PREVIEW_URL}/en)`),
expect.stringContaining(
`[/en/download](${MOCK_VERCEL_PREVIEW_URL}/en/download)`
),
const call = mockCore.setOutput.mock.calls[0];
const expectedOutput = [
/\/en\]\(https:\/\/some.vercel.preview.url\/en\)/,
/\/en\/download\]\(https:\/\/some.vercel.preview.url\/en\/download\)/,
];

expectations.forEach(expectation => {
expect(mockCore.setOutput).toBeCalledWith('comment', expectation);
strictEqual(call.arguments[0], 'comment');
expectedOutput.forEach(expected => {
ok(call.arguments[1].match(expected));
});
});

it('formats stoplight colors correctly', () => {
formatLighthouseResults({ core: mockCore });

const expectations = [
expect.stringContaining(`🟢 90`),
expect.stringContaining(`🟠 75`),
expect.stringContaining(`🔴 49`),
];
const call = mockCore.setOutput.mock.calls[0];
const expectedOutput = [/🟢 99/, /🟠 75/, /🔴 49/];

expectations.forEach(expectation => {
expect(mockCore.setOutput).toBeCalledWith('comment', expectation);
strictEqual(call.arguments[0], 'comment');
expectedOutput.forEach(expected => {
ok(call.arguments[1].match(expected));
});
});
});

0 comments on commit 93887e8

Please sign in to comment.