canvas-lms/jest.config.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3.8 KiB
JavaScript
Raw Normal View History

/*
babel independence(3): jest refs FOO-2697 flag = none on "babel-plugin-transform-imports": the behavior of this plugin was surprising to me in that it not only rewrote the specifiers to point to the CommonJS instead of the ESM variants, but it actually changed the specifiers to point to the exact file that exports the symbol through a mixture of fs globbing and guesses. Consider the following import: import { DateTime } from '@instructure/ui-i18n' Normally, you'd think we'll be loading the {main,module,browser} file of the @instructure/ui-i18n package and refer to the `DateTime` symbol exported by that file. With the plugin activated, however, the import *itself* changes to: import DateTime from '@instructure/ui-i18n/lib/DateTime.js' This is no longer merely a variant rewrite in any way as we're no longer loading the same file. This caused new problems to surface that up to this point were not encountered, as now we're actually loading the entrypoints as specified. An example of this is in that specific package where it (its entrypoint) loads a package `decimal.js` whose ESM variant doesn't work as-is but its CJS variant does -- something neither we nor the InstUI team were privy to as the plugin was simply clobbering this piece of information. ~ test plan ~ - jest suite runs and passes Change-Id: I55d7db1ede742e0f588a84d54a761b7aba03729f Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/283543 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Aaron Shafovaloff <ashafovaloff@instructure.com> QA-Review: Aaron Shafovaloff <ashafovaloff@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2022-01-25 23:25:15 +08:00
* Copyright (C) 2022 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const {defaults} = require('jest-config')
module.exports = {
moduleNameMapper: {
'\\.svg$': '<rootDir>/jest/imageMock.js',
add conference ui to calendar details page refs CAL-4 flag=calendar_conferences Test plan: - enable FF "Add Conferences from Calendar" and "Allow Conference Selection..." - enable BigBlueButton with dummy settings at /plugins/big_blue_button - create two courses, one with multiple sections - add LTI tool for conference selection to one course - open add calendar event dialog at /calendar - switch context to one of the courses - verify that conferencing options appear (two options if in course with LTI; one option otherwise) - click more options to open detailed edit page - verify that conferencing options appear the same way - add a conference - save the conference - verify that conference appears on the calendar - repeat in the other context to verify other select UI - add a conference before clicking "more options" and verify that it is included in the more options page - verfy that updating the conference and then cancelling on the more options page does not save the update - in the course with multiple sections, select "use a different date for each section" - verify that the conference for the parent event is shown for each of the child events in the calendar - verify that the conference can't be edited from the child events - verify that updating the parent event conference from the More Details page also updates the child events (as seen in the calendar) Change-Id: I9a7dccc9962d3c056f6a6a5fdb8a501ce8960c18 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/235298 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Ken McGrady <kmcgrady@instructure.com> QA-Review: Steve Shepherd <sshepherd@instructure.com> Product-Review: Michael Brewer-Davis <mbd@instructure.com>
2020-04-25 00:55:53 +08:00
'node_modules-version-of-backbone': require.resolve('backbone'),
'node_modules-version-of-react-modal': require.resolve('react-modal'),
'^Backbone$': '<rootDir>/public/javascripts/Backbone.js',
// jest can't import the icons
'@instructure/ui-icons/es/svg': '<rootDir>/packages/canvas-rce/src/rce/__tests__/_mockIcons.js',
// redirect imports from es/rce to lib
'@instructure/canvas-rce/es/rce/tinyRCE': '<rootDir>/packages/canvas-rce/lib/rce/tinyRCE.js',
'@instructure/canvas-rce/es/rce/RCE': '<rootDir>/packages/canvas-rce/lib/rce/RCE.js',
Detect B&I on File upload refs MAT-364 flag=rce_buttons_and_icons This commit causes the File upload UI to tag button and icons that are uploaded as button and icons. Note that this change does not yet apply the correct cateagory if an image is uploaded via the "documents" tool in RCE Test Plan: Note that this test plan involves a fair amount of regression testing because this change touches the upload code used in /files 1. Rebuild canvas-rce JS and canvas-lms webpack. Run DB migrations if it's been a bit 2. Make sure you've pulled down the latest canvas-rce-api code and have it running 3. Enable buttons & icons in if you've not already 4. Create a button & icon 6. Navigate to to the course files and download the buton and icon to your computer 7. Delete the button and icon from the "Buttons and Icons" folder in the course files 8. In an RCE in the same course, open the "saved buttons & icons" tray. Note that the button & icon you previously downloaded and deleted is not listed. 9. Navigte to course files and create a new folder. It can be named anything, just make sure not to nest it in the "Buttons and Icons" folder. 10. Upload the image downloaded in step 6 into the new folder 11. Navigate to an RCE and open the "saved buttons & icons" tray 12. validate the image you uploaded in step 10 is listed \o/ 13. Verify you can upload non-images to course files still 14. Verify you can upload a zipped file to course files still. This should give the option of unzipping or leaving zipped. make sure both paths work 15. Upload a file and then attempt to upload the same file. This should result in a collision of names. Verify you can choose the option to replace the file with success. Do the same thing again, but verify you can rename the file with success 16. Verify you can upload files in batches with success Change-Id: I0fc0ffa45f5b4757a347ebe631461eb3e00bb25e Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/284085 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jacob DeWar <jacob.dewar@instructure.com> QA-Review: Jacob DeWar <jacob.dewar@instructure.com> Product-Review: Weston Dransfield <wdransfield@instructure.com>
2022-02-02 03:37:54 +08:00
'@instructure/canvas-rce/es/rce/plugins/shared/Upload/CategoryProcessor':
'<rootDir>/packages/canvas-rce/lib/rce/plugins/shared/Upload/CategoryProcessor',
// mock the tinymce-react Editor react component
babel independence(3): jest refs FOO-2697 flag = none on "babel-plugin-transform-imports": the behavior of this plugin was surprising to me in that it not only rewrote the specifiers to point to the CommonJS instead of the ESM variants, but it actually changed the specifiers to point to the exact file that exports the symbol through a mixture of fs globbing and guesses. Consider the following import: import { DateTime } from '@instructure/ui-i18n' Normally, you'd think we'll be loading the {main,module,browser} file of the @instructure/ui-i18n package and refer to the `DateTime` symbol exported by that file. With the plugin activated, however, the import *itself* changes to: import DateTime from '@instructure/ui-i18n/lib/DateTime.js' This is no longer merely a variant rewrite in any way as we're no longer loading the same file. This caused new problems to surface that up to this point were not encountered, as now we're actually loading the entrypoints as specified. An example of this is in that specific package where it (its entrypoint) loads a package `decimal.js` whose ESM variant doesn't work as-is but its CJS variant does -- something neither we nor the InstUI team were privy to as the plugin was simply clobbering this piece of information. ~ test plan ~ - jest suite runs and passes Change-Id: I55d7db1ede742e0f588a84d54a761b7aba03729f Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/283543 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Aaron Shafovaloff <ashafovaloff@instructure.com> QA-Review: Aaron Shafovaloff <ashafovaloff@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2022-01-25 23:25:15 +08:00
'@tinymce/tinymce-react': '<rootDir>/packages/canvas-rce/src/rce/__mocks__/tinymceReact.js',
'decimal.js/decimal.mjs': 'decimal.js/decimal.js'
},
roots: ['<rootDir>/ui', 'gems/plugins', 'public/javascripts'],
moduleDirectories: ['ui/shims', 'public/javascripts', 'node_modules'],
reporters: [
'default',
[
'jest-junit',
{
suiteName: 'Jest Tests',
outputDirectory: process.env.TEST_RESULT_OUTPUT_DIR || './coverage-js/junit-reports',
outputName: 'jest.xml',
addFileAttribute: 'true'
}
]
],
snapshotSerializers: ['enzyme-to-json/serializer'],
setupFiles: ['jest-localstorage-mock', 'jest-canvas-mock', '<rootDir>/jest/jest-setup.js'],
Upgrade to babel 7 & allow any js file to be themeable closes: CORE-2699 CORE-2700 UIDEV-99 This commit gets canvas-lms itself upgraded to babel 7. To do that we also had to upgrade jest to v24. We had already got canvas-rce and canvas-planner on jest24/babel7 but now this gets everything to babel 7. so you will see a lot of things removed from yarn.lock since we don’t don’t have to have different versions of everything for babel and jest The other major thing this does is make it so any JS file in canvas can become an @instructure/ui-themeable themeable component. This means you no longer should have to put your css in app/stylesheets for any new react components that you are writing. Test plan: 1. Make sure that the perf of `yarn build:js` is on-par with what it was before. We pass everything through the themeable babel transform now so there is a chance it is slower. If it is majorly slower, we’ll have to figure something out. 2. run a production weback build. The common (or any bundle for that matter should get output exactly the same as it did before) things to manually qa check: * in a NODE_ENV=production enviornment, go to /accounts/site_admin/developer_keys * click the "+ Developer Key" button, it should open the modal. (there are selenium tests that do this, but it was one thing that had to be fixed to get jenkins to pass) * on a course that is set up as a master course, click on the thing that opens the blueprint courses tray. * verify that when you click "Associations" and "Sync History" links in that tray, that they dynamically load the webpack chunk for the modal contents for that thing and then the modal is shown (again, there are selenium specs that test that exact thing but it is always good to manually test it too) Change-Id: I802584228962b54480a500f8fe422f45c2dcac4c Reviewed-on: https://gerrit.instructure.com/183965 Tested-by: Jenkins Reviewed-by: Clay Diffrient <cdiffrient@instructure.com> QA-Review: Ryan Shaw <ryan@instructure.com> Product-Review: Ryan Shaw <ryan@instructure.com>
2019-03-06 05:20:27 +08:00
setupFilesAfterEnv: [
'@testing-library/jest-dom/extend-expect',
'./packages/validated-apollo/src/ValidatedApolloCleanup.js',
'<rootDir>/jest/stubRecursiveTimers.js'
Upgrade to babel 7 & allow any js file to be themeable closes: CORE-2699 CORE-2700 UIDEV-99 This commit gets canvas-lms itself upgraded to babel 7. To do that we also had to upgrade jest to v24. We had already got canvas-rce and canvas-planner on jest24/babel7 but now this gets everything to babel 7. so you will see a lot of things removed from yarn.lock since we don’t don’t have to have different versions of everything for babel and jest The other major thing this does is make it so any JS file in canvas can become an @instructure/ui-themeable themeable component. This means you no longer should have to put your css in app/stylesheets for any new react components that you are writing. Test plan: 1. Make sure that the perf of `yarn build:js` is on-par with what it was before. We pass everything through the themeable babel transform now so there is a chance it is slower. If it is majorly slower, we’ll have to figure something out. 2. run a production weback build. The common (or any bundle for that matter should get output exactly the same as it did before) things to manually qa check: * in a NODE_ENV=production enviornment, go to /accounts/site_admin/developer_keys * click the "+ Developer Key" button, it should open the modal. (there are selenium tests that do this, but it was one thing that had to be fixed to get jenkins to pass) * on a course that is set up as a master course, click on the thing that opens the blueprint courses tray. * verify that when you click "Associations" and "Sync History" links in that tray, that they dynamically load the webpack chunk for the modal contents for that thing and then the modal is shown (again, there are selenium specs that test that exact thing but it is always good to manually test it too) Change-Id: I802584228962b54480a500f8fe422f45c2dcac4c Reviewed-on: https://gerrit.instructure.com/183965 Tested-by: Jenkins Reviewed-by: Clay Diffrient <cdiffrient@instructure.com> QA-Review: Ryan Shaw <ryan@instructure.com> Product-Review: Ryan Shaw <ryan@instructure.com>
2019-03-06 05:20:27 +08:00
],
Initial pace plans import This change brings in the basic pace plans frontend with styled-components and several other smaller libraries replaced with InstUI 7 components. It also adds the 'reselect' library as a direct dependency (which we already had through @instructure/outcomes-ui) and 'tsc-files' for type-checking of staged TS files on commit. There were also some tweaks to typescript and eslint configs, mostly to get both up to speed with the typescript code. Finally, this also adds a `pace_plans` endpoint to `courses_controller` to bootstrap the frontend-- this will get moved to `pace_plans_controller` once it has been merged. It's also worth noting that no frontend tests are included with this change-- the existing tests were written with enzyme and are heavily snapshot-based, so we will be replacing those with @testing-library/react tests in later updates (in keeping with current testing best practices at Instructure). closes LS-2431, LS-2432, LS-2433, LS-2434, LS-2452 flag = pace_plans Test plan: - Set up a course with at least one module and several module items - Turn on the pace_plans feature flag in the account associated with that course - Turn on the "Enable pace plans" setting in course settings - Create a pace plan for the course via the Rails console: c = Course.find<id> pp = c.pace_plans.create! workflow_state: 'active' c.context_module_tags.each_with_index do |t, i| pp.pace_plan_module_items.create! module_item: t, duration: i*2 end - Go to the course as a teacher or admin - Expect to see a "Pace Plans" link in the course navigation - Click it, expect the pace plan you created earlier to load and render - Expect to be able to pick dates, change durations, and toggle checkboxes (although saves will fail, since there is no API yet). - Expect to not see the "Pace Plans" course nav link when the feature flag or course setting is off - Expect /courses/<id>/pace_plans to return a 404 when the feature flag or course setting is off - Expect to not see the "Pace Plans" course nav link as a student - Expect /courses/<id>/pace_plans to display an "Unauthorized" page as a student Change-Id: If4dc5d17f2c6a2109d4b4cb652c9e9ef00d7cc33 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/271650 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Ed Schiebel <eschiebel@instructure.com> QA-Review: Ed Schiebel <eschiebel@instructure.com> Product-Review: Jeff Largent <jeff.largent@instructure.com>
2021-08-18 05:14:24 +08:00
testMatch: ['**/__tests__/**/?(*.)(spec|test).[jt]s?(x)'],
coverageDirectory: '<rootDir>/coverage-jest/',
// skip flaky timeout tests from coverage until they can be addressed
// Related JIRA tickets for the skipped coverage tests;
// k5_dashboard: LS-2243
collectCoverageFrom: [
'**/__tests__/**/?(*.)(spec|test).[jt]s?(x)',
'!<rootDir>/ui/features/k5_dashboard/react/__tests__/k5DashboardPlanner.test.js'
],
moduleFileExtensions: [...defaults.moduleFileExtensions, 'coffee', 'handlebars'],
restoreMocks: true,
testEnvironment: 'jsdom',
testSequencer: '<rootDir>/jest/test-sequencer.js',
transform: {
babel independence(3): jest refs FOO-2697 flag = none on "babel-plugin-transform-imports": the behavior of this plugin was surprising to me in that it not only rewrote the specifiers to point to the CommonJS instead of the ESM variants, but it actually changed the specifiers to point to the exact file that exports the symbol through a mixture of fs globbing and guesses. Consider the following import: import { DateTime } from '@instructure/ui-i18n' Normally, you'd think we'll be loading the {main,module,browser} file of the @instructure/ui-i18n package and refer to the `DateTime` symbol exported by that file. With the plugin activated, however, the import *itself* changes to: import DateTime from '@instructure/ui-i18n/lib/DateTime.js' This is no longer merely a variant rewrite in any way as we're no longer loading the same file. This caused new problems to surface that up to this point were not encountered, as now we're actually loading the entrypoints as specified. An example of this is in that specific package where it (its entrypoint) loads a package `decimal.js` whose ESM variant doesn't work as-is but its CJS variant does -- something neither we nor the InstUI team were privy to as the plugin was simply clobbering this piece of information. ~ test plan ~ - jest suite runs and passes Change-Id: I55d7db1ede742e0f588a84d54a761b7aba03729f Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/283543 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Aaron Shafovaloff <ashafovaloff@instructure.com> QA-Review: Aaron Shafovaloff <ashafovaloff@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2022-01-25 23:25:15 +08:00
'\\.coffee$': '<rootDir>/jest/coffeeTransformer.js',
'\\.handlebars$': '<rootDir>/jest/handlebarsTransformer.js',
'\\.graphql$': 'jest-raw-loader',
'\\.[jt]sx?$': [
'babel-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: 'commonjs'
}
],
['@babel/preset-react', {useBuiltIns: true}],
['@babel/preset-typescript', {}]
],
targets: {
node: 'current'
}
}
]
}
}