Przeglądaj źródła

Add webpack as part of the smoketest

Alex Dima 3 lat temu
rodzic
commit
dfe35b15bb

+ 6 - 0
.github/workflows/ci.yml

@@ -41,5 +41,11 @@ jobs:
       - name: Run unit tests
       - name: Run unit tests
         run: npm test
         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
       - name: Run smoke test
         run: npm run smoketest
         run: npm run smoketest

+ 0 - 2
.gitignore

@@ -1,5 +1,3 @@
 **/node_modules/
 **/node_modules/
 **/out/
 **/out/
 **/release/
 **/release/
-/webpack-plugin/test/dist/*.js
-/webpack-plugin/test/dist/*.ttf

+ 3 - 4
.prettierignore

@@ -1,4 +1,6 @@
-/out/
+**/node_modules/
+**/out/
+**/release/
 /monaco-editor-samples/browser-esm-parcel/.cache/
 /monaco-editor-samples/browser-esm-parcel/.cache/
 /monaco-editor-samples/browser-esm-parcel/dist/
 /monaco-editor-samples/browser-esm-parcel/dist/
 /monaco-editor-samples/browser-esm-vite-react/dist/**/*.js
 /monaco-editor-samples/browser-esm-vite-react/dist/**/*.js
@@ -12,7 +14,4 @@
 /monaco-editor/typedoc/theme/
 /monaco-editor/typedoc/theme/
 /monaco-editor/typedoc/monaco.d.ts
 /monaco-editor/typedoc/monaco.d.ts
 /monaco-editor/website/lib/
 /monaco-editor/website/lib/
-/webpack-plugin/test/dist/*.js
-/webpack-plugin/out/
-/release/
 /src/typescript/lib/
 /src/typescript/lib/

+ 3 - 1
test/smoke/amd.html

@@ -12,7 +12,9 @@
 					vs: '../../release/dev/vs'
 					vs: '../../release/dev/vs'
 				}
 				}
 			});
 			});
-			require(['vs/editor/editor.main'], () => {});
+			require(['vs/editor/editor.main'], () => {
+				window.monacoAPI = monaco;
+			});
 		</script>
 		</script>
 	</body>
 	</body>
 </html>
 </html>

+ 12 - 5
test/smoke/runner.js

@@ -35,14 +35,21 @@ yaserver
 	});
 	});
 
 
 async function runTests() {
 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) => {
 	return new Promise((resolve, reject) => {
-		const env = { BROWSER: browser, ...process.env };
+		const env = { BROWSER: browser, TESTS_TYPE: type, ...process.env };
 		if (DEBUG_TESTS) {
 		if (DEBUG_TESTS) {
 			env['DEBUG_TESTS'] = 'true';
 			env['DEBUG_TESTS'] = 'true';
 		}
 		}

+ 9 - 4
test/smoke/amd.test.js → test/smoke/smoke.test.js

@@ -11,7 +11,12 @@ const { PORT } = require('./common');
 
 
 const browserType = process.env.BROWSER || 'chromium';
 const browserType = process.env.BROWSER || 'chromium';
 const DEBUG_TESTS = Boolean(process.env.DEBUG_TESTS || false);
 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} */
 /** @type {playwright.Browser} */
 let browser;
 let browser;
@@ -59,8 +64,8 @@ afterEach(async () => {
 });
 });
 
 
 describe('Smoke Test', () => {
 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) {
 	async function createEditor(text, language) {
 		return await page.evaluate(
 		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}' })`
 		);
 		);
 	}
 	}
 
 

+ 10 - 0
test/smoke/webpack/webpack.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+	</head>
+	<body>
+		<div id="editor-container" style="position: absolute; width: 500px; height: 400px"></div>
+		<script type="text/javascript" src="out/app.js"></script>
+	</body>
+</html>

+ 2 - 1
webpack-plugin/.npmignore

@@ -1,2 +1,3 @@
+/scripts/
 /src/
 /src/
-/test/
+/smoketest/

+ 3 - 2
webpack-plugin/package.json

@@ -5,11 +5,12 @@
 	"main": "out/index.js",
 	"main": "out/index.js",
 	"typings": "./out/index.d.ts",
 	"typings": "./out/index.d.ts",
 	"scripts": {
 	"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",
 		"test-cross-origin": "node ./node_modules/webpack/bin/webpack.js --config test/webpack-cross-origin.config.js --progress",
 		"watch": "tsc -w -p tsconfig.json",
 		"watch": "tsc -w -p tsconfig.json",
+		"compile": "tsc -p tsconfig.json",
 		"import-editor": "node ./scripts/import-editor.js",
 		"import-editor": "node ./scripts/import-editor.js",
-		"prepublishOnly": "tsc -p tsconfig.json"
+		"prepublishOnly": "npm run compile"
 	},
 	},
 	"repository": {
 	"repository": {
 		"type": "git",
 		"type": "git",

+ 4 - 0
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;

+ 0 - 0
webpack-plugin/test/webpack-cross-origin.config.js → webpack-plugin/smoketest/webpack-cross-origin.config.js


+ 5 - 3
webpack-plugin/test/webpack.config.js → webpack-plugin/smoketest/webpack.config.js

@@ -1,17 +1,19 @@
 const MonacoWebpackPlugin = require('../out/index.js');
 const MonacoWebpackPlugin = require('../out/index.js');
 const path = require('path');
 const path = require('path');
 
 
+const REPO_ROOT = path.join(__dirname, '../../');
+
 module.exports = {
 module.exports = {
 	mode: 'development',
 	mode: 'development',
 	entry: './index.js',
 	entry: './index.js',
 	context: __dirname,
 	context: __dirname,
 	output: {
 	output: {
-		path: path.resolve(__dirname, 'dist'),
+		path: path.resolve(REPO_ROOT, 'test/smoke/webpack/out'),
 		filename: 'app.js'
 		filename: 'app.js'
 	},
 	},
 	resolve: {
 	resolve: {
 		alias: {
 		alias: {
-			'monaco-editor': path.resolve(__dirname, '../../release')
+			'monaco-editor': path.resolve(REPO_ROOT, 'release')
 		}
 		}
 	},
 	},
 	module: {
 	module: {
@@ -28,7 +30,7 @@ module.exports = {
 	},
 	},
 	plugins: [
 	plugins: [
 		new MonacoWebpackPlugin({
 		new MonacoWebpackPlugin({
-			monacoEditorPath: path.resolve(__dirname, '../../release')
+			monacoEditorPath: path.resolve(REPO_ROOT, 'release')
 		})
 		})
 	]
 	]
 };
 };

+ 0 - 13
webpack-plugin/test/dist/index.html

@@ -1,13 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-	<head>
-		<meta charset="UTF-8" />
-		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
-		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
-		<title>Document</title>
-	</head>
-	<body>
-		<div id="container" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>
-		<script type="text/javascript" src="app.js"></script>
-	</body>
-</html>

+ 0 - 6
webpack-plugin/test/index.js

@@ -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'
-});