diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7875347..311f2148 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,5 +41,11 @@ jobs: - name: Run unit tests run: npm test + - name: Build webpack plugin + run: npm run compile --prefix webpack-plugin + + - name: Package using webpack plugin + run: npm run smoketest --prefix webpack-plugin + - name: Run smoke test run: npm run smoketest diff --git a/.gitignore b/.gitignore index 59d33ffa..fb0dff55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ **/node_modules/ **/out/ **/release/ -/webpack-plugin/test/dist/*.js -/webpack-plugin/test/dist/*.ttf diff --git a/.prettierignore b/.prettierignore index 51b88097..f514ab1f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,6 @@ -/out/ +**/node_modules/ +**/out/ +**/release/ /monaco-editor-samples/browser-esm-parcel/.cache/ /monaco-editor-samples/browser-esm-parcel/dist/ /monaco-editor-samples/browser-esm-vite-react/dist/**/*.js @@ -12,7 +14,4 @@ /monaco-editor/typedoc/theme/ /monaco-editor/typedoc/monaco.d.ts /monaco-editor/website/lib/ -/webpack-plugin/test/dist/*.js -/webpack-plugin/out/ -/release/ /src/typescript/lib/ diff --git a/test/smoke/amd.html b/test/smoke/amd.html index be747d1f..0992c8c3 100644 --- a/test/smoke/amd.html +++ b/test/smoke/amd.html @@ -12,7 +12,9 @@ vs: '../../release/dev/vs' } }); - require(['vs/editor/editor.main'], () => {}); + require(['vs/editor/editor.main'], () => { + window.monacoAPI = monaco; + }); diff --git a/test/smoke/runner.js b/test/smoke/runner.js index 2f6bf4b0..a51b828b 100644 --- a/test/smoke/runner.js +++ b/test/smoke/runner.js @@ -35,14 +35,21 @@ yaserver }); async function runTests() { - await runTest('chromium'); - await runTest('firefox'); - // await runTest('webkit'); + for (const type of ['amd', 'webpack']) { + await runTest(type, 'chromium'); + await runTest(type, 'firefox'); + // await runTest(type, 'webkit'); + } } -function runTest(browser) { +/** + * @param {string} type + * @param {'chromium'|'firefox'|'webkit'} browser + * @returns + */ +function runTest(type, browser) { return new Promise((resolve, reject) => { - const env = { BROWSER: browser, ...process.env }; + const env = { BROWSER: browser, TESTS_TYPE: type, ...process.env }; if (DEBUG_TESTS) { env['DEBUG_TESTS'] = 'true'; } diff --git a/test/smoke/amd.test.js b/test/smoke/smoke.test.js similarity index 90% rename from test/smoke/amd.test.js rename to test/smoke/smoke.test.js index 6b08f82c..65758322 100644 --- a/test/smoke/amd.test.js +++ b/test/smoke/smoke.test.js @@ -11,7 +11,12 @@ const { PORT } = require('./common'); const browserType = process.env.BROWSER || 'chromium'; const DEBUG_TESTS = Boolean(process.env.DEBUG_TESTS || false); -const URL = `http://127.0.0.1:${PORT}/test/smoke/amd.html`; +const TESTS_TYPE = process.env.TESTS_TYPE || 'amd'; + +const URL = + TESTS_TYPE === 'amd' + ? `http://127.0.0.1:${PORT}/test/smoke/amd.html` + : `http://127.0.0.1:${PORT}/test/smoke/webpack/webpack.html`; /** @type {playwright.Browser} */ let browser; @@ -59,8 +64,8 @@ afterEach(async () => { }); describe('Smoke Test', () => { - it('`monaco` is exposed as global', async () => { - assert.strictEqual(await page.evaluate(`typeof monaco`), 'object'); + it('`monacoAPI` is exposed as global', async () => { + assert.strictEqual(await page.evaluate(`typeof monacoAPI`), 'object'); }); /** @@ -70,7 +75,7 @@ describe('Smoke Test', () => { */ async function createEditor(text, language) { return await page.evaluate( - `window.ed = monaco.editor.create(document.getElementById('editor-container'), { value: '${text}', language: '${language}' })` + `window.ed = monacoAPI.editor.create(document.getElementById('editor-container'), { value: '${text}', language: '${language}' })` ); } diff --git a/test/smoke/webpack/webpack.html b/test/smoke/webpack/webpack.html new file mode 100644 index 00000000..a7107bda --- /dev/null +++ b/test/smoke/webpack/webpack.html @@ -0,0 +1,10 @@ + + + + + + +
+ + + diff --git a/webpack-plugin/.npmignore b/webpack-plugin/.npmignore index 6f816447..b032262a 100644 --- a/webpack-plugin/.npmignore +++ b/webpack-plugin/.npmignore @@ -1,2 +1,3 @@ +/scripts/ /src/ -/test/ +/smoketest/ diff --git a/webpack-plugin/package.json b/webpack-plugin/package.json index ba23125e..27637d81 100644 --- a/webpack-plugin/package.json +++ b/webpack-plugin/package.json @@ -5,11 +5,12 @@ "main": "out/index.js", "typings": "./out/index.d.ts", "scripts": { - "test": "node ./node_modules/webpack/bin/webpack.js --config test/webpack.config.js --progress", + "smoketest": "node ./node_modules/webpack/bin/webpack.js --config smoketest/webpack.config.js --progress", "test-cross-origin": "node ./node_modules/webpack/bin/webpack.js --config test/webpack-cross-origin.config.js --progress", "watch": "tsc -w -p tsconfig.json", + "compile": "tsc -p tsconfig.json", "import-editor": "node ./scripts/import-editor.js", - "prepublishOnly": "tsc -p tsconfig.json" + "prepublishOnly": "npm run compile" }, "repository": { "type": "git", diff --git a/webpack-plugin/smoketest/index.js b/webpack-plugin/smoketest/index.js new file mode 100644 index 00000000..f4e62ee8 --- /dev/null +++ b/webpack-plugin/smoketest/index.js @@ -0,0 +1,4 @@ +import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; + +// expose the monaco API as a global for tests +window.monacoAPI = monaco; diff --git a/webpack-plugin/test/webpack-cross-origin.config.js b/webpack-plugin/smoketest/webpack-cross-origin.config.js similarity index 100% rename from webpack-plugin/test/webpack-cross-origin.config.js rename to webpack-plugin/smoketest/webpack-cross-origin.config.js diff --git a/webpack-plugin/test/webpack.config.js b/webpack-plugin/smoketest/webpack.config.js similarity index 66% rename from webpack-plugin/test/webpack.config.js rename to webpack-plugin/smoketest/webpack.config.js index a387f882..88c7edc6 100644 --- a/webpack-plugin/test/webpack.config.js +++ b/webpack-plugin/smoketest/webpack.config.js @@ -1,17 +1,19 @@ const MonacoWebpackPlugin = require('../out/index.js'); const path = require('path'); +const REPO_ROOT = path.join(__dirname, '../../'); + module.exports = { mode: 'development', entry: './index.js', context: __dirname, output: { - path: path.resolve(__dirname, 'dist'), + path: path.resolve(REPO_ROOT, 'test/smoke/webpack/out'), filename: 'app.js' }, resolve: { alias: { - 'monaco-editor': path.resolve(__dirname, '../../release') + 'monaco-editor': path.resolve(REPO_ROOT, 'release') } }, module: { @@ -28,7 +30,7 @@ module.exports = { }, plugins: [ new MonacoWebpackPlugin({ - monacoEditorPath: path.resolve(__dirname, '../../release') + monacoEditorPath: path.resolve(REPO_ROOT, 'release') }) ] }; diff --git a/webpack-plugin/test/dist/index.html b/webpack-plugin/test/dist/index.html deleted file mode 100644 index 2efdede0..00000000 --- a/webpack-plugin/test/dist/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - Document - - -
- - - diff --git a/webpack-plugin/test/index.js b/webpack-plugin/test/index.js deleted file mode 100644 index bab166dd..00000000 --- a/webpack-plugin/test/index.js +++ /dev/null @@ -1,6 +0,0 @@ -import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; - -monaco.editor.create(document.getElementById('container'), { - value: 'console.log("Hello, world")', - language: 'javascript' -});