diff --git a/.eslintrc.json b/.eslintrc.json index f758a8d45..0536dd5ab 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,6 +14,7 @@ "coverage/**", "demos/*/qunit/**", "demos/*/coverage/**", + "demos/*/dist/**", "demos/*/package-lock.json", "docs/.jekyll-cache/**", "docs/_site/**", @@ -190,7 +191,7 @@ } }, { - "files": ["demos/**/*.js"], + "files": ["demos/**/*.js", "demos/**/*.mjs"], "env": { "browser": true, "es2017": true, diff --git a/.gitignore b/.gitignore index c5c2d9ded..6749b61d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ /coverage/ /demos/*/package-lock.json /demos/*/node_modules/ +/demos/*/dist/ +/demos/rollup/test-*.html /docs/.jekyll-cache/ /docs/_site/ /docs/Gemfile.lock diff --git a/demos/rollup.js b/demos/rollup.js new file mode 100644 index 000000000..ab4b9bd48 --- /dev/null +++ b/demos/rollup.js @@ -0,0 +1,77 @@ +const cp = require('child_process'); +const path = require('path'); +const DIR = path.join(__dirname, 'rollup'); + +function normalize (str) { + return str + .replace(/^localhost:\d+/g, 'localhost:8000') + .replace(/\b\d+ms\b/g, '42ms'); +} + +QUnit.module('rollup', { + before: () => { + cp.execSync('npm install --prefer-offline --no-audit --update-notifier=false', { cwd: DIR, encoding: 'utf8' }); + cp.execSync('npx npm run build', { cwd: DIR, encoding: 'utf8' }); + } +}); + +QUnit.test('test', assert => { + const expected = `Running "connect:all" (connect) task +Started connect web server on http://localhost:8000 + +Running "qunit:all" (qunit) task +Testing http://localhost:8000/test-import-default-from-cjs.es.html .OK +>> passed test "import default from qunit.cjs > example" +Testing http://localhost:8000/test-import-default-from-cjs.iife.html .OK +>> passed test "import default from qunit.cjs > example" +Testing http://localhost:8000/test-import-default-from-cjs.umd.html .OK +>> passed test "import default from qunit.cjs > example" +Testing http://localhost:8000/test-import-from-cjs.es.html .OK +>> passed test "import { module,test } from qunit.cjs > example" +Testing http://localhost:8000/test-import-from-cjs.iife.html .OK +>> passed test "import { module,test } from qunit.cjs > example" +Testing http://localhost:8000/test-import-from-cjs.umd.html .OK +>> passed test "import { module,test } from qunit.cjs > example" +Testing http://localhost:8000/test-mixed-to-import.es.html ....OK +>> passed test "import default from qunit.cjs > example" +>> passed test "import { module,test } from qunit.cjs > example" +>> passed test "require from qunit.cjs > example" +>> passed test "mixed" +Testing http://localhost:8000/test-mixed-to-import.iife.html ....OK +>> passed test "import default from qunit.cjs > example" +>> passed test "import { module,test } from qunit.cjs > example" +>> passed test "require from qunit.cjs > example" +>> passed test "mixed" +Testing http://localhost:8000/test-mixed-to-import.umd.html ....OK +>> passed test "import default from qunit.cjs > example" +>> passed test "import { module,test } from qunit.cjs > example" +>> passed test "require from qunit.cjs > example" +>> passed test "mixed" +Testing http://localhost:8000/test-mixed-to-require.es.html ....OK +>> passed test "import default from qunit.cjs > example" +>> passed test "import { module,test } from qunit.cjs > example" +>> passed test "require from qunit.cjs > example" +>> passed test "mixed" +Testing http://localhost:8000/test-mixed-to-require.iife.html ....OK +>> passed test "import default from qunit.cjs > example" +>> passed test "import { module,test } from qunit.cjs > example" +>> passed test "require from qunit.cjs > example" +>> passed test "mixed" +Testing http://localhost:8000/test-mixed-to-require.umd.html ....OK +>> passed test "import default from qunit.cjs > example" +>> passed test "import { module,test } from qunit.cjs > example" +>> passed test "require from qunit.cjs > example" +>> passed test "mixed" +Testing http://localhost:8000/test-require-from-cjs.es.html .OK +>> passed test "require from qunit.cjs > example" +Testing http://localhost:8000/test-require-from-cjs.iife.html .OK +>> passed test "require from qunit.cjs > example" +Testing http://localhost:8000/test-require-from-cjs.umd.html .OK +>> passed test "require from qunit.cjs > example" +>> 33 tests completed in 42ms, with 0 failed, 0 skipped, and 0 todo. + +Done.`; + + const actual = cp.execSync('npx npm -s test', { cwd: DIR, env: { PATH: process.env.PATH }, encoding: 'utf8' }); + assert.equal(normalize(actual).trim(), expected); +}); diff --git a/demos/rollup/Gruntfile.js b/demos/rollup/Gruntfile.js new file mode 100644 index 000000000..5d780e89f --- /dev/null +++ b/demos/rollup/Gruntfile.js @@ -0,0 +1,39 @@ +/* eslint-env node */ +module.exports = function (grunt) { + grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + + grunt.initConfig({ + connect: { + all: { + options: { + useAvailablePort: true, + base: '.' + } + } + }, + qunit: { + options: { + }, + all: ['test-*.html'] + } + }); + + grunt.event.once('connect.all.listening', function (_host, port) { + grunt.config('qunit.options.httpBase', `http://localhost:${port}`); + // console.log(grunt.config()); // DEBUG + }); + + let results = []; + grunt.event.on('qunit.on.testEnd', function (test) { + results.push( + `>> ${test.status} test "${test.fullName.join(' > ')}"` + ); + }); + grunt.event.on('qunit.on.runEnd', function () { + grunt.log.writeln(results.join('\n')); + results = []; + }); + + grunt.registerTask('test', ['connect', 'qunit']); +}; diff --git a/demos/rollup/build.mjs b/demos/rollup/build.mjs new file mode 100644 index 000000000..846157ea7 --- /dev/null +++ b/demos/rollup/build.mjs @@ -0,0 +1,103 @@ +import fs from 'node:fs'; + +import { rollup } from 'rollup'; +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; + +const plugins = [commonjs(), resolve()]; + +const inputs = [ + { + input: 'test/test-import-default-from-cjs.js', + plugins + }, + { + input: 'test/test-import-from-cjs.js', + plugins + }, + { + input: 'test/test-mixed-to-import.js', + plugins + }, + { + input: 'test/test-mixed-to-require.js', + plugins, + // Ignore "output.name" warning for test-require-from-cjs.iife.js + onwarn: () => {} + }, + { + input: 'test/test-require-from-cjs.js', + plugins, + // Ignore "output.name" warning for test-require-from-cjs.iife.js + onwarn: () => {} + } +]; +const outputs = [ + { + dir: 'dist/', + entryFileNames: '[name].[format].js', + format: 'es' + }, + { + dir: 'dist/', + entryFileNames: '[name].[format].js', + format: 'cjs' + }, + { + dir: 'dist/', + entryFileNames: '[name].[format].js', + format: 'iife' + }, + { + dir: 'dist/', + entryFileNames: '[name].[format].js', + format: 'umd', + name: 'UNUSED' + } +]; +const htmlTemplate = ` + + +
+