Skip to content

Commit

Permalink
chore: reinstate prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Aug 14, 2024
1 parent d2045aa commit 8c7e869
Show file tree
Hide file tree
Showing 54 changed files with 1,286 additions and 950 deletions.
60 changes: 33 additions & 27 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import globals from 'globals';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
export default [
{
ignores: [
'docs/**/*.js',
Expand All @@ -15,42 +15,48 @@ export default tseslint.config(
'packages/fetch-mock/types/index.test-d.ts',
],
},
eslint.configs.recommended,
...tseslint.configs.recommended,
eslintConfigPrettier,
{
rules: {
'no-prototype-builtins': 0,
'@typescript-eslint/no-wrapper-object-types': 0
'@typescript-eslint/no-wrapper-object-types': 0,
},
languageOptions: {
globals: {
...globals.node,
}
}
},
},
},
{
files: [
'import-compat/*',
'**/*.cjs',
'packages/fetch-mock/test/framework-compat/jest.spec.js',
'packages/fetch-mock/test/fixtures/fetch-proxy.js'
],
rules: {
'@typescript-eslint/no-require-imports': 0
},

files: [
'import-compat/*',
'**/*.cjs',
'packages/fetch-mock/test/fixtures/fetch-proxy.js',
],
rules: {
'@typescript-eslint/no-require-imports': 0,
},
{
files: ['packages/fetch-mock/test/**/*.js'],
languageOptions: {globals: {
},
{
files: ['packages/fetch-mock/test/**/*.js'],
languageOptions: {
globals: {
testGlobals: 'writable',
}},
},
},
{
files: ['packages/fetch-mock/test/fixtures/sw.js'],
languageOptions: {globals: {
...globals.browser
}},
}
);
},
{
files: ['packages/fetch-mock/test/fixtures/sw.js'],
languageOptions: {
globals: {
...globals.browser,
},
},
},
eslintPluginPrettierRecommended,
];

// module.exports = {
// env: {
Expand Down
10 changes: 5 additions & 5 deletions import-compat/ts-cjs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {default: fetchMockCore, FetchMock} = require("@fetch-mock/core");
fetchMockCore.route("http://example.com", 200);
const { default: fetchMockCore, FetchMock } = require('@fetch-mock/core');
fetchMockCore.route('http://example.com', 200);

new FetchMock({})
new FetchMock({});

const fetchMock = require("fetch-mock").default;
fetchMock.mock("http://example.com", 200);
const fetchMock = require('fetch-mock').default;
fetchMock.mock('http://example.com', 200);
10 changes: 5 additions & 5 deletions import-compat/ts-esm.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetchMockCore, {FetchMock} from "@fetch-mock/core";
fetchMockCore.route("http://example.com", 200);
import fetchMockCore, { FetchMock } from '@fetch-mock/core';
fetchMockCore.route('http://example.com', 200);

new FetchMock({})
new FetchMock({});

import fetchMock from "fetch-mock";
fetchMock.mock("http://example.com", 200);
import fetchMock from 'fetch-mock';
fetchMock.mock('http://example.com', 200);
10 changes: 5 additions & 5 deletions import-compat/ts-esm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetchMockCore, {FetchMock} from "@fetch-mock/core";
fetchMockCore.route("http://example.com", 200);
import fetchMockCore, { FetchMock } from '@fetch-mock/core';
fetchMockCore.route('http://example.com', 200);

new FetchMock({})
new FetchMock({});

import fetchMock from "fetch-mock";
fetchMock.mock("http://example.com", 200);
import fetchMock from 'fetch-mock';
fetchMock.mock('http://example.com', 200);
90 changes: 90 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"@vitest/coverage-v8": "^2.0.5",
"@vitest/ui": "^2.0.5",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.9.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
Expand Down
36 changes: 21 additions & 15 deletions packages/core/src/CallHistory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { createCallLogFromUrlAndOptions, NormalizedRequestOptions } from './RequestUtils.js';
import {
createCallLogFromUrlAndOptions,
NormalizedRequestOptions,
} from './RequestUtils.js';
import { isUrlMatcher, RouteMatcher } from './Matchers.js';
import Route, {RouteConfig, RouteName} from './Route.js';
import Route, { RouteConfig, RouteName } from './Route.js';
import Router from './Router.js';
import type { FetchMockConfig } from "./FetchMock.js";
import type { FetchMockConfig } from './FetchMock.js';

export type Matched = "matched";
export type Unmatched = "unmatched";
export type CallHistoryFilter = RouteName | Matched | Unmatched | boolean | RouteMatcher;
export type Matched = 'matched';
export type Unmatched = 'unmatched';
export type CallHistoryFilter =
| RouteName
| Matched
| Unmatched
| boolean
| RouteMatcher;
export type CallLog = {
args: unknown[];
url: string;
Expand All @@ -27,9 +35,11 @@ const isName = (filter: CallHistoryFilter): filter is RouteName =>
/^[\da-zA-Z-]+$/.test(filter) &&
!['matched', 'unmatched'].includes(filter);

const isMatchedOrUnmatched = (filter: CallHistoryFilter): filter is (Matched | Unmatched | boolean) =>
const isMatchedOrUnmatched = (
filter: CallHistoryFilter,
): filter is Matched | Unmatched | boolean =>
typeof filter === 'boolean' ||
(['matched', 'unmatched']).includes(filter as string);
['matched', 'unmatched'].includes(filter as string);

class CallHistory {
callLogs: CallLog[];
Expand Down Expand Up @@ -62,21 +72,17 @@ class CallHistory {
await this.flush();
}
}
calls(filter: CallHistoryFilter, options: RouteConfig): CallLog[]{
calls(filter: CallHistoryFilter, options: RouteConfig): CallLog[] {
let calls = [...this.callLogs];
if (typeof filter === 'undefined' && !options) {
return calls;
}

if (isMatchedOrUnmatched(filter)) {
if (
([true, 'matched'] as CallHistoryFilter[]).includes(filter)
) {
if (([true, 'matched'] as CallHistoryFilter[]).includes(filter)) {
calls = calls.filter(({ route }) => !route.config.isFallback);
} else if (
([false, 'unmatched'] as CallHistoryFilter[]).includes(
filter,
)
([false, 'unmatched'] as CallHistoryFilter[]).includes(filter)
) {
calls = calls.filter(({ route }) => Boolean(route.config.isFallback));
}
Expand Down
Loading

0 comments on commit 8c7e869

Please sign in to comment.