From 058c3de97507daf2497e1c625302d64183143fbc Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Thu, 27 Apr 2023 23:41:30 +0200 Subject: [PATCH] Remove Rollup pre-proccesor from Karma runner (#8935) --- .github/workflows/main.yml | 2 +- CONTRIBUTING.md | 19 +++--- package-lock.json | 23 ------- package.json | 1 - spec/index.html | 121 ------------------------------------- spec/karma.conf.js | 97 ++++------------------------- 6 files changed, 25 insertions(+), 238 deletions(-) delete mode 100644 spec/index.html diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1691ec50398..a6c2a4ac3cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -125,7 +125,7 @@ jobs: node-version: ${{ env.NODE_VERSION }} - name: Run tests on ${{ matrix.browser }} - run: npm test -- --browsers ${{ matrix.browser }} + run: npm test -- --browsers ${{ matrix.browser }} --single-run publish-artifacts: needs: setup diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96dc8dafda7..c4ea321ac55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -97,7 +97,7 @@ Also, please make sure that you have [line endings configured properly](https:// Happy coding! -### Using RollupJS +### Building Leaflet The source JavaScript code for Leaflet is a few dozen files, in the `src/` directory. But normally, Leaflet is loaded in a web browser as just one JavaScript file. @@ -110,7 +110,7 @@ development. `dist/leaflet.js` is uglified and thus is smaller, so it's better for deployment. When developing (or bugfixing) core Leaflet functionalities, it's common to use -the webpages in the `debug/` directory, and run the unit tests (`spec/index.html`) +the webpages in the `debug/` directory, and run the tests in a graphical browser. This requires regenerating the bundled files quickly. In order to do so, run `npm run watch` or `yarn run watch`. This will keep @@ -118,21 +118,24 @@ on rebuilding the bundles whenever any source file changes. ## Running the Tests -To run the tests from the command line, install [Google Chrome](https://www.google.com/chrome/) then run: +Before running the tests make sure that the source code has been built (as mentioned above). If you want to run the tests in the background while working on Leaflet it is recommended you run the build in `watch` mode. This way the tests will automatically re-run when changes to the source code are made. + +To run the tests from the command line, ensure you have [Google Chrome](https://www.google.com/chrome/) installed and then run: ``` npm test ``` -To run the tests in other browsers at the same time, you can do: +By default the tests will run in Google Chrome headlessly (without a UI), to run the tests in other browsers you can pass in the [`--browsers`](https://karma-runner.github.io/latest/config/configuration-file.html#browsers) flag. ``` -npm test -- -- --browsers Firefox,Chrome,Safari,IE +npm test -- --browsers Firefox ``` -(Note: the doubling of "`--`" [special option](https://docs.npmjs.com/cli/run-script#description) is [important](https://github.com/Leaflet/Leaflet/pull/6166#issuecomment-390959903)) - -To run the tests in a browser manually, open `spec/index.html`. +For a list of available browsers see the documentation of the included launcher plugins: +- [`karma-chrome-launcher`](https://github.com/karma-runner/karma-chrome-launcher#available-browsers) +- [`karma-firefox-launcher`](https://github.com/karma-runner/karma-firefox-launcher#configuration) +- [`karma-safarinative-launcher`](https://github.com/muthu90ec/karma-safarinative-launcher#readme) ## Improving Documentation diff --git a/package-lock.json b/package-lock.json index a81851c0ca2..ddf88557920 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "karma-expect": "^1.1.3", "karma-firefox-launcher": "^2.1.2", "karma-mocha": "^2.0.1", - "karma-rollup-preprocessor": "^7.0.8", "karma-safarinative-launcher": "^1.1.0", "karma-sinon": "^1.0.5", "karma-time-stats-reporter": "^0.1.0", @@ -1292,12 +1291,6 @@ "node": ">=4.0" } }, - "node_modules/debounce": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.1.tgz", - "integrity": "sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==", - "dev": true - }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3169,22 +3162,6 @@ "minimist": "^1.2.3" } }, - "node_modules/karma-rollup-preprocessor": { - "version": "7.0.8", - "resolved": "https://registry.npmjs.org/karma-rollup-preprocessor/-/karma-rollup-preprocessor-7.0.8.tgz", - "integrity": "sha512-WiuBCS9qsatJuR17dghiTARBZ7LF+ml+eb7qJXhw7IbsdY0lTWELDRQC/93J9i6636CsAXVBL3VJF4WtaFLZzA==", - "dev": true, - "dependencies": { - "chokidar": "^3.3.1", - "debounce": "^1.2.0" - }, - "engines": { - "node": ">= 8.0.0" - }, - "peerDependencies": { - "rollup": ">= 1.0.0" - } - }, "node_modules/karma-safarinative-launcher": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/karma-safarinative-launcher/-/karma-safarinative-launcher-1.1.0.tgz", diff --git a/package.json b/package.json index 56d7fef553f..994f02f1f1e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "karma-expect": "^1.1.3", "karma-firefox-launcher": "^2.1.2", "karma-mocha": "^2.0.1", - "karma-rollup-preprocessor": "^7.0.8", "karma-safarinative-launcher": "^1.1.0", "karma-sinon": "^1.0.5", "karma-time-stats-reporter": "^0.1.0", diff --git a/spec/index.html b/spec/index.html deleted file mode 100644 index 07b29792821..00000000000 --- a/spec/index.html +++ /dev/null @@ -1,121 +0,0 @@ - - - - - Leaflet Spec Runner - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spec/karma.conf.js b/spec/karma.conf.js index a7097e43c2b..063ce06d7d5 100644 --- a/spec/karma.conf.js +++ b/spec/karma.conf.js @@ -1,32 +1,8 @@ -const json = require('@rollup/plugin-json'); - -// Karma configuration -module.exports = function (config) { - - // var libSources = require(__dirname + '/../build/build.js').getFiles(); - - const files = [ - 'spec/before.js', - 'src/LeafletWithGlobals.js', - 'spec/after.js', - 'node_modules/ui-event-simulator/ui-event-simulator.js', - 'node_modules/prosthetic-hand/dist/prosthetic-hand.js', - 'spec/suites/SpecHelper.js', - 'spec/suites/**/*.js', - 'dist/*.css', - {pattern: 'dist/images/*.png', included: false, serve: true} - ]; - - const preprocessors = {}; - - preprocessors['src/LeafletWithGlobals.js'] = ['rollup']; - +// See: https://karma-runner.github.io/latest/config/configuration-file.html +module.exports = function (/** @type {import('karma').Config} */ config) { config.set({ - // base path, that will be used to resolve files and exclude basePath: '../', - plugins: [ - 'karma-rollup-preprocessor', 'karma-mocha', 'karma-sinon', 'karma-expect', @@ -35,61 +11,28 @@ module.exports = function (config) { 'karma-firefox-launcher', 'karma-time-stats-reporter' ], - - // frameworks to use frameworks: ['mocha', 'sinon', 'expect'], - - // list of files / patterns to load in the browser - files, + files: [ + 'spec/before.js', + {pattern: 'dist/leaflet-src.js'}, + 'spec/after.js', + 'node_modules/ui-event-simulator/ui-event-simulator.js', + 'node_modules/prosthetic-hand/dist/prosthetic-hand.js', + 'spec/suites/SpecHelper.js', + 'spec/suites/**/*.js', + 'dist/*.css', + {pattern: 'dist/images/*.png', included: false, served: true} + ], proxies: { '/base/dist/images/': 'dist/images/' }, - exclude: [], - - // Rollup the ES6 Leaflet sources into just one file, before tests - preprocessors, - rollupPreprocessor: { - onwarn: () => {}, // silence Rollup warnings - plugins: [ - json() - ], - output: { - format: 'umd', - name: 'leaflet', - freeze: false, - }, - }, - - // test results reporter to use - // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' reporters: ['progress', 'time-stats'], - timeStatsReporter: { reportTimeStats: false, longestTestsCount: 10 }, - - // web server port - port: 9876, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_WARN, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // Start these browsers, currently available: - // - Chrome - // - ChromeCanary - // - Firefox - // - Opera - // - SafariNative (only Mac) browsers: ['Chrome1280x1024'], - customLaunchers: { 'Chrome1280x1024': { base: 'ChromeHeadless', @@ -116,22 +59,8 @@ module.exports = function (config) { } } }, - concurrency: 1, - - // If browser does not capture in given timeout [ms], kill it - captureTimeout: 60000, - - // Timeout for the client socket connection [ms]. - browserSocketTimeout: 30000, - - // Silence console.warn output in the terminal browserConsoleLogOptions: {level: 'error'}, - - // Continuous Integration mode - // if true, it capture browsers, run tests and exit - singleRun: true, - client: { mocha: { // eslint-disable-next-line no-undef