Skip to content

Commit

Permalink
fix: support typescript 4.4.x, 4.5.x, 4.6.x (#1245)
Browse files Browse the repository at this point in the history
* fix: support typescript 4.4.x, 4.5.x, 4.6.x

* test(hard-reload): use "location.replace"
  • Loading branch information
kettanaito committed May 20, 2022
1 parent 0233a9e commit 5378416
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -44,7 +44,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ts: ['4.2', '4.3']
ts: ['4.2', '4.3', '4.4', '4.5', '4.6']
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -135,13 +135,13 @@
"ts-jest": "26",
"ts-loader": "^9.2.6",
"ts-node": "^10.1.0",
"typescript": "^4.3.5",
"typescript": "^4.6.4",
"url-loader": "^4.1.1",
"webpack": "^5.68.0",
"webpack-dev-server": "^3.11.2"
},
"peerDependencies": {
"typescript": "4.2.x || 4.3.x"
"typescript": ">= 4.2.x <= 4.6.x"
},
"peerDependenciesMeta": {
"typescript": {
Expand All @@ -156,4 +156,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
2 changes: 1 addition & 1 deletion src/utils/internal/parseGraphQLRequest.ts
Expand Up @@ -44,7 +44,7 @@ function parseQuery(query: string): ParsedGraphQLQuery | Error {
const ast = parse(query)
return parseDocumentNode(ast)
} catch (error) {
return error
return error as Error
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/internal/tryCatch.ts
Expand Up @@ -6,6 +6,6 @@ export function tryCatch<Fn extends (...args: any[]) => any>(
const result = fn()
return result
} catch (error) {
onException?.(error)
onException?.(error as Error)
}
}
28 changes: 15 additions & 13 deletions src/utils/worker/createRequestListener.ts
Expand Up @@ -80,19 +80,21 @@ export const createRequestListener = (
})
}

// Treat all the other exceptions in a request handler
// as unintended, alerting that there is a problem needs fixing.
channel.send({
type: 'INTERNAL_ERROR',
payload: {
status: 500,
body: JSON.stringify({
errorType: error.constructor.name,
message: error.message,
location: error.stack,
}),
},
})
if (error instanceof Error) {
// Treat all the other exceptions in a request handler
// as unintended, alerting that there is a problem needs fixing.
channel.send({
type: 'INTERNAL_ERROR',
payload: {
status: 500,
body: JSON.stringify({
errorType: error.constructor.name,
message: error.message,
location: error.stack,
}),
},
})
}
}
}
}
11 changes: 9 additions & 2 deletions test/msw-api/hard-reload.test.ts
Expand Up @@ -10,8 +10,15 @@ function createRuntime() {
test('keeps the mocking enabled after hard-reload of the page', async () => {
const runtime = await createRuntime()

// Passing `true` to `location.reload()` forces a hard reload
runtime.page.evaluate(() => location.reload(true))
runtime.page.evaluate(() => {
/**
* Emulate a forced reload.
* Since `location.reload(true)` is deprecated,
* use a workaround.
* @see https://stackoverflow.com/a/65544086/2754939
*/
location.replace(location.href)
})

await runtime.page.waitForNavigation({
waitUntil: 'networkidle',
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -9366,16 +9366,16 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.3.5:
version "4.3.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==

typescript@^4.4.3:
version "4.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8"
integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==

typescript@^4.6.4:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==

unicode-canonical-property-names-ecmascript@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"
Expand Down

0 comments on commit 5378416

Please sign in to comment.