Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions actions/collectPageActivity/getURL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class InvalidURLError extends Error {
readonly url: string;
readonly base: string | undefined;

constructor(message: string, url: string, base: string | undefined) {
super(message);

this.name = 'InvalidURLError';
this.url = url;
this.base = base;

//https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, InvalidURLError.prototype);

Error.captureStackTrace?.(this, this.constructor);
}

toJSON() {
const { url, base } = this;

return {
url,
base,
};
}
}

export function getURL(url: string, base?: string) {
try {
return new URL(url, base);
} catch {
let message: string;

if (base === undefined) {
message = 'isSameResponse: failed to create URL for url %s';
} else {
message = 'isSameResponse: failed to create URL for url %s and base %s';
}

console.error(message, url, base);

throw new InvalidURLError('isSameResponse: failed to create url', url, base);
}
}
6 changes: 4 additions & 2 deletions actions/collectPageActivity/isSameResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getURL } from './getURL';
import { normalizePathname } from './normalizePathname';
import type { ExpectedResponse } from './types';

Expand All @@ -7,13 +8,14 @@ export function isSameResponse(status: number, url: string, baseUrl: string) {
return (expectedResponse: ExpectedResponse) => {
const expectedUrl =
typeof expectedResponse.url === 'string'
? new URL(expectedResponse.url, baseUrl)
? getURL(expectedResponse.url, baseUrl)
: expectedResponse.url;
const failedUrl = new URL(url);

let result = expectedResponse.status === status;

if (result) {
const failedUrl = getURL(url);

if (expectedUrl instanceof RegExp) {
result = expectedUrl.test(failedUrl.href);
} else {
Expand Down
53 changes: 0 additions & 53 deletions config/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions config/browsers.ts

This file was deleted.

28 changes: 0 additions & 28 deletions config/browsersDesktop.ts

This file was deleted.

21 changes: 0 additions & 21 deletions config/browsersMobile.ts

This file was deleted.

42 changes: 33 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,42 @@
"/data/**/*.*(js|d.ts)",
"/fixtures/**/*.*(js|d.ts)",
"/har/**/*.*(js|d.ts)",
"/storybook/**/*.*(js|d.ts)",
"/utils/**/*.*(js|d.ts)",
"!/**/__tests__"
],
"exports": [
"./actions/**/*.*(js|d.ts)",
"./auth/**/*.*(js|d.ts)",
"./config/**/*.*(js|d.ts)",
"./data/**/*.*(js|d.ts)",
"./fixtures/**/*.*(js|d.ts)",
"./har/**/*.*(js|d.ts)",
"./utils/**/*.*(js|d.ts)"
],
"exports": {
"./actions": {
"types": "./actions/index.d.ts",
"import": "./actions/index.js",
"require": "./actions/index.js"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just use default here, instead of import+require with the same target?

"default" - the generic fallback that always matches. Can be a CommonJS or ES module file. This condition should always come last.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, lets keep it as is. If sometime later we will need to separate commonjs and module APIs, we will need to go back to this place.

Some verbosity here is ok IMO

},
"./auth/storage": {
"types": "./auth/storage/index.d.ts",
"import": "./auth/storage/index.js",
"require": "./auth/storage/index.js"
},
"./fixtures": {
"types": "./fixtures/index.d.ts",
"import": "./fixtures/index.js",
"require": "./fixtures/index.js"
},
"./har": {
"types": "./har/index.d.ts",
"import": "./har/index.js",
"require": "./har/index.js"
},
"./storybook": {
"types": "./storybook/index.d.ts",
"import": "./storybook/index.js",
"require": "./storybook/index.js"
},
"./utils": {
"types": "./utils/index.d.ts",
"import": "./utils/index.js",
"require": "./utils/index.js"
}
},
"scripts": {
"prepare": "husky",
"build": "tsc",
Expand Down
2 changes: 2 additions & 0 deletions storybook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { Cases, CasesWithName, Scenario, ScenarioName } from './types';
export { createSmokeScenarios } from './create-smoke-scenarios';
Loading