From 4e7a01c07503e3064bbaf1b47a3e06ff67a84683 Mon Sep 17 00:00:00 2001 From: Aaron Shafovaloff Date: Wed, 17 Jan 2024 15:59:11 -0700 Subject: [PATCH] use JSC in Jest instead of Babel Removing Babel in Jest ensures we won't add more of the CommonJS-presuming mutative funny-business that Babel enabled flag=none Change-Id: I02a8b7387ff79c6f44b4304bfeb8e15ec26f787c Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/337966 QA-Review: Aaron Shafovaloff Product-Review: Aaron Shafovaloff Reviewed-by: Isaac Moore Tested-by: Service Cloud Jenkins --- jest.config.js | 28 +- package.json | 1 + tsconfig.json | 2 +- .../AttemptType/__tests__/FileUpload.test.jsx | 15 +- .../legacy_migrator_wrapper.test.tsx | 8 +- .../__tests__/ConfigurationForm.test.tsx | 9 +- .../Item/__tests__/ItemAssignToCard.test.tsx | 3 +- yarn.lock | 239 +++++++++++++----- 8 files changed, 202 insertions(+), 103 deletions(-) diff --git a/jest.config.js b/jest.config.js index 8cb3abbf3af..d19f8e0d879 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,6 +17,7 @@ */ const {defaults} = require('jest-config') +const {swc} = require('./ui-build/webpack/webpack.rules') const esModules = ['mime'].join('|') @@ -79,25 +80,16 @@ module.exports = { transform: { '\\.handlebars$': '/jest/handlebarsTransformer.js', '\\.graphql$': '/jest/rawLoader.js', - '\\.[jt]sx?$': [ - 'babel-jest', + '^.+\\.(j|t)s?$': [ + '@swc/jest', { - configFile: false, - presets: [ - [ - '@babel/preset-env', - { - // until we're on Jest 27 and can look into loading ESMs natively; - // https://jestjs.io/docs/ecmascript-modules - modules: 'auto', - }, - ], - ['@babel/preset-react', {useBuiltIns: true}], - ['@babel/preset-typescript', {}], - ], - targets: { - node: 'current', - }, + jsc: swc[0].use.options.jsc, + }, + ], + '^.+\\.(j|t)sx?$': [ + '@swc/jest', + { + jsc: swc[1].use.options.jsc, }, ], }, diff --git a/package.json b/package.json index e7b95321915..2ce413db7a4 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "@sentry/fullstory": "^1.1.7", "@sentry/react": "^7.81.0", "@swc/core": "^1.3.102", + "@swc/jest": "^0.2.29", "@swc/helpers": "^0.5.3", "@tanstack/query-sync-storage-persister": "^4.36.1", "@tanstack/react-query": "^4.36.1", diff --git a/tsconfig.json b/tsconfig.json index 4e2f5ff111e..de0e1944efb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "allowJs": true, // allows importing of .js files from .ts files "esModuleInterop": true, // more accurately transpiles to the ES6 module spec (maybe not needed w/ babel transpilation) "isolatedModules": true, // required to adhere to babel's single-file transpilation process - "jsx": "react", // transpiles jsx to React.createElement calls (maybe not needed w/ babel transpilation) + "jsx": "react-jsx", // transpiles jsx to React.createElement calls (maybe not needed w/ babel transpilation) "lib": ["DOM", "ES2020", "ESNext"], // include types for DOM APIs and standard JS up to ES2020 "incremental": true, // enables incremental compilation for faster builds "module": "es2020", // support the most modern ES6-style module syntax diff --git a/ui/features/assignments_show_student/react/components/AttemptType/__tests__/FileUpload.test.jsx b/ui/features/assignments_show_student/react/components/AttemptType/__tests__/FileUpload.test.jsx index 3ce8f7593ae..a315599b02d 100644 --- a/ui/features/assignments_show_student/react/components/AttemptType/__tests__/FileUpload.test.jsx +++ b/ui/features/assignments_show_student/react/components/AttemptType/__tests__/FileUpload.test.jsx @@ -74,15 +74,16 @@ async function makeProps(overrides) { return props } -beforeAll(() => { - $('body').append('