Skip to content

Commit

Permalink
Merge pull request #141 from openstax/k12-581/dependency-updates
Browse files Browse the repository at this point in the history
Update dependency versions
  • Loading branch information
rnathuji authored Jan 24, 2024
2 parents c2ba594 + f29b796 commit 785ce8c
Show file tree
Hide file tree
Showing 33 changed files with 2,034 additions and 1,637 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = {
'vite.config.ts',
'jest.config.ts',
'jest.setup.ts',
'jest.polyfills.js',
'jest.resolver.js',
'playwright.config.ts',
'coverage',
'.eslintrc.js'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20.11.0"
- name: Setup
run: |
npm install
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.18.0
v20.11.0
2 changes: 1 addition & 1 deletion deploy-authoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
phases:
install:
commands:
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- export NVM_DIR="$HOME/.nvm"
- cd /tmp && . "$NVM_DIR/nvm.sh" && cd $CODEBUILD_SRC_DIR && nvm install
pre_build:
Expand Down
2 changes: 1 addition & 1 deletion deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
phases:
install:
commands:
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- export NVM_DIR="$HOME/.nvm"
- cd /tmp && . "$NVM_DIR/nvm.sh" && cd $CODEBUILD_SRC_DIR && nvm install
pre_build:
Expand Down
6 changes: 5 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default {
moduleNameMapper: {
'^mathlive$': '<rootDir>/node_modules/mathlive'
},
setupFiles: ['<rootDir>/jest.setup.ts'],
setupFiles: [
'<rootDir>/jest.setup.ts',
'<rootDir>/jest.polyfills.js'
],
resolver: '<rootDir>/jest.resolver.js',
verbose: true
}
32 changes: 32 additions & 0 deletions jest.polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// The following is as prescribed in docs at https://mswjs.io/docs/migrations/1.x-to-2.x#requestresponsetextencoder-is-not-defined-jest

// jest.polyfills.js
/**
* @note The block below contains polyfills for Node.js globals
* required for Jest to function when running JSDOM tests.
* These HAVE to be require's and HAVE to be in this exact
* order, since "undici" depends on the "TextEncoder" global API.
*
* Consider migrating to a more modern test runner if
* you don't want to deal with this.
*/

const { TextDecoder, TextEncoder } = require('node:util')

Object.defineProperties(globalThis, {
TextDecoder: { value: TextDecoder },
TextEncoder: { value: TextEncoder },
})

const { Blob, File } = require('node:buffer')
const { fetch, Headers, FormData, Request, Response } = require('undici')

Object.defineProperties(globalThis, {
fetch: { value: fetch, writable: true },
Blob: { value: Blob },
File: { value: File },
Headers: { value: Headers },
FormData: { value: FormData },
Request: { value: Request },
Response: { value: Response },
})
34 changes: 34 additions & 0 deletions jest.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// A hack inspired by https://github.com/mswjs/msw/issues/1786#issuecomment-1786122056 since the
// prescribed https://mswjs.io/docs/migrations/1.x-to-2.x#cannot-find-module-mswnode-jsdom
// broke other things

module.exports = (path, options) => {
// Jest + jsdom acts like a browser (i.e., it looks for "browser" imports
// under pkg.exports), but msw knows that you're operating in a Node
// environment:
//
// https://github.com/mswjs/msw/issues/1786#issuecomment-1782559851
//
// The MSW project's recommended workaround is to disable Jest's
// customExportConditions completely, so no packages use their browser's
// versions. We'll instead clear export conditions only for MSW.
if (/^(msw|@mswjs\/interceptors)(\/|$)/.test(path)) {
return options.defaultResolver(
path,
{
...options,
packageFilter: (pkg) => {
if (pkg.name === 'msw') {
delete pkg.exports['./node'].browser
}
if (pkg.name === '@mswjs/interceptors') {
delete pkg.exports
}

return pkg
},
})
}

return options.defaultResolver(path, options)
}
Loading

0 comments on commit 785ce8c

Please sign in to comment.