浏览代码

Bring smoketest scripts together (#3370)

Alexandru Dima 2 年之前
父节点
当前提交
2b3d8516c6

+ 1 - 1
.github/workflows/ci.yml

@@ -48,7 +48,7 @@ jobs:
         run: npm run compile --prefix webpack-plugin
 
       - name: Package using webpack plugin
-        run: npm run package-for-smoketest --prefix webpack-plugin
+        run: npm run package-for-smoketest-webpack
 
       - name: Package using esbuild
         run: npm run package-for-smoketest-esbuild

文件差异内容过多而无法显示
+ 829 - 9
package-lock.json


+ 6 - 0
package.json

@@ -17,6 +17,8 @@
 		"pretty-quick": "pretty-quick --staged",
 		"release": "ts-node ./build/build && ts-node ./build/release",
 		"simpleserver": "ts-node ./build/simpleserver",
+		"package-for-smoketest-webpack": "ts-node ./test/smoke/package-webpack",
+		"package-for-smoketest-webpack-cross-origin": "ts-node ./test/smoke/package-webpack --cross-origin",
 		"package-for-smoketest-esbuild": "ts-node ./test/smoke/package-esbuild",
 		"package-for-smoketest-vite": "ts-node ./test/smoke/package-vite",
 		"smoketest": "node ./test/smoke/runner.js",
@@ -38,8 +40,10 @@
 		"@typescript/vfs": "^1.3.5",
 		"chai": "^4.3.6",
 		"clean-css": "^5.2.4",
+		"css-loader": "^6.7.1",
 		"esbuild": "^0.14.49",
 		"esbuild-plugin-alias": "^0.2.1",
+		"file-loader": "^6.2.0",
 		"glob": "^7.2.0",
 		"husky": "^7.0.4",
 		"jsdom": "^19.0.0",
@@ -50,6 +54,7 @@
 		"prettier": "^2.5.1",
 		"pretty-quick": "^3.1.3",
 		"requirejs": "^2.3.6",
+		"style-loader": "^3.3.1",
 		"terser": "^5.14.2",
 		"ts-node": "^10.6.0",
 		"typedoc": "^0.22.11",
@@ -61,6 +66,7 @@
 		"vscode-languageserver-textdocument": "^1.0.4",
 		"vscode-languageserver-types": "3.16.0",
 		"vscode-uri": "3.0.3",
+		"webpack": "^5.74.0",
 		"yaserver": "^0.4.0"
 	}
 }

+ 2 - 2
test/smoke/amd.html → test/smoke/amd/index.html

@@ -5,11 +5,11 @@
 	</head>
 	<body>
 		<div id="editor-container" style="position: absolute; width: 500px; height: 400px"></div>
-		<script src="../../release/dev/vs/loader.js"></script>
+		<script src="../../../release/dev/vs/loader.js"></script>
 		<script>
 			require.config({
 				paths: {
-					vs: '../../release/dev/vs'
+					vs: '../../../release/dev/vs'
 				}
 			});
 			require(['vs/editor/editor.main'], () => {

+ 6 - 1
test/smoke/common.js

@@ -3,4 +3,9 @@
  *  Licensed under the MIT License. See License.txt in the project root for license information.
  *--------------------------------------------------------------------------------------------*/
 
-exports.PORT = 8563;
+/* keeping TS happy */
+exports.__nothing = undefined;
+
+/** @typedef {'chromium'|'firefox'|'webkit'} BrowserKind */
+/** @typedef {'amd'|'webpack'|'esbuild'|'vite'} PackagerKind */
+/** @typedef {{browser:BrowserKind; packager:PackagerKind; debugTests:boolean; port:number;}} TestInfo */

+ 0 - 0
test/smoke/esbuild/esbuild.html → test/smoke/esbuild/index.html


+ 1 - 1
test/smoke/package-esbuild.ts

@@ -7,7 +7,7 @@ import * as esbuild from 'esbuild';
 import * as path from 'path';
 import { removeDir } from '../../build/fs';
 
-removeDir('test/smoke/esbuild/out', (entry) => /esbuild.html$/.test(entry));
+removeDir('test/smoke/esbuild/out');
 
 const workerEntryPoints = [
 	'vs/language/json/json.worker.js',

+ 56 - 0
test/smoke/package-webpack.ts

@@ -0,0 +1,56 @@
+/*---------------------------------------------------------------------------------------------
+ *  Copyright (c) Microsoft Corporation. All rights reserved.
+ *  Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+import webpack from 'webpack';
+import MonacoWebpackPlugin from '../../webpack-plugin/out/index.js';
+import * as path from 'path';
+
+const REPO_ROOT = path.join(__dirname, '../../');
+const CROSS_ORIGIN_ASSETS = process.argv.includes('--cross-origin');
+
+webpack(
+	{
+		mode: 'development',
+		entry: './index.js',
+		context: path.join(__dirname, 'webpack'),
+		output: {
+			path: path.resolve(REPO_ROOT, 'test/smoke/webpack/out'),
+			filename: 'app.js',
+			publicPath: CROSS_ORIGIN_ASSETS
+				? 'http://localhost:8088/monaco-editor/test/smoke/webpack/out/'
+				: undefined
+		},
+		resolve: {
+			alias: {
+				'monaco-editor': path.resolve(REPO_ROOT, 'release')
+			}
+		},
+		module: {
+			rules: [
+				{
+					test: /\.css$/,
+					use: ['style-loader', 'css-loader']
+				},
+				{
+					test: /\.ttf$/,
+					use: ['file-loader']
+				}
+			]
+		},
+		plugins: [<any>new MonacoWebpackPlugin({
+				monacoEditorPath: path.resolve(REPO_ROOT, 'release')
+			})]
+	},
+	(err: Error | undefined, stats: webpack.Stats | undefined) => {
+		if (err) {
+			console.error(err);
+			process.exit(1);
+		}
+		if (stats && stats.hasErrors()) {
+			console.log(stats.compilation.errors);
+			process.exit(1);
+		}
+	}
+);

+ 18 - 10
test/smoke/runner.js

@@ -9,10 +9,14 @@ const yaserver = require('yaserver');
 const http = require('http');
 const cp = require('child_process');
 const path = require('path');
-const { PORT } = require('./common');
-const DEBUG_TESTS = process.argv.includes('--debug-tests');
 
+/** @typedef {import('./common').BrowserKind} BrowserKind */
+/** @typedef {import('./common').PackagerKind} PackagerKind */
+/** @typedef {import('./common').TestInfo} TestInfo */
+
+const DEBUG_TESTS = process.argv.includes('--debug-tests');
 const REPO_ROOT = path.join(__dirname, '../../');
+const PORT = 8563;
 
 yaserver
 	.createServer({
@@ -37,7 +41,7 @@ yaserver
 async function runTests() {
 	// uncomment to shortcircuit and run a specific combo
 	// await runTest('webpack', 'chromium'); return;
-	/** @type {('amd'|'webpack'|'esbuild'|'vite')[]} */
+	/** @type {PackagerKind[]} */
 	const testTypes = ['amd', 'webpack', 'esbuild', 'vite'];
 
 	for (const type of testTypes) {
@@ -48,16 +52,20 @@ async function runTests() {
 }
 
 /**
- * @param {'amd'|'webpack'|'esbuild'|'vite'} type
- * @param {'chromium'|'firefox'|'webkit'} browser
+ * @param {PackagerKind} packager
+ * @param {BrowserKind} browser
  * @returns
  */
-function runTest(type, browser) {
+function runTest(packager, browser) {
 	return new Promise((resolve, reject) => {
-		const env = { BROWSER: browser, TESTS_TYPE: type, ...process.env };
-		if (DEBUG_TESTS) {
-			env['DEBUG_TESTS'] = 'true';
-		}
+		/** @type TestInfo */
+		const testInfo = {
+			browser,
+			packager,
+			debugTests: DEBUG_TESTS,
+			port: PORT
+		};
+		const env = { MONACO_TEST_INFO: JSON.stringify(testInfo), ...process.env };
 		const proc = cp.spawn(
 			'node',
 			[

+ 16 - 14
test/smoke/smoke.test.js

@@ -7,21 +7,23 @@
 
 const playwright = require('playwright');
 const { assert } = require('chai');
-const { PORT } = require('./common');
 
-const browserType = process.env.BROWSER || 'chromium';
-const DEBUG_TESTS = Boolean(process.env.DEBUG_TESTS || false);
-const TESTS_TYPE = process.env.TESTS_TYPE || 'amd';
+/** @typedef {import('./common').BrowserKind} BrowserKind */
+/** @typedef {import('./common').PackagerKind} PackagerKind */
+/** @typedef {import('./common').TestInfo} TestInfo */
+
+/** @type TestInfo */
+const testInfo = JSON.parse(process.env.MONACO_TEST_INFO || '');
 
 const URLS = {
-	amd: `http://127.0.0.1:${PORT}/test/smoke/amd.html`,
-	webpack: `http://127.0.0.1:${PORT}/test/smoke/webpack/webpack.html`,
-	esbuild: `http://127.0.0.1:${PORT}/test/smoke/esbuild/esbuild.html`,
-	vite: `http://127.0.0.1:${PORT}/test/smoke/vite/dist/index.html`
+	amd: `http://127.0.0.1:${testInfo.port}/test/smoke/amd/index.html`,
+	webpack: `http://127.0.0.1:${testInfo.port}/test/smoke/webpack/index.html`,
+	esbuild: `http://127.0.0.1:${testInfo.port}/test/smoke/esbuild/index.html`,
+	vite: `http://127.0.0.1:${testInfo.port}/test/smoke/vite/dist/index.html`
 };
-const URL = URLS[TESTS_TYPE];
+const URL = URLS[testInfo.packager];
 
-suite(`Smoke Test '${TESTS_TYPE}' on '${browserType}'`, () => {
+suite(`Smoke Test '${testInfo.packager}' on '${testInfo.browser}'`, () => {
 	/** @type {playwright.Browser} */
 	let browser;
 
@@ -29,10 +31,10 @@ suite(`Smoke Test '${TESTS_TYPE}' on '${browserType}'`, () => {
 	let page;
 
 	suiteSetup(async () => {
-		browser = await playwright[browserType].launch({
-			headless: !DEBUG_TESTS,
-			devtools: DEBUG_TESTS && browserType === 'chromium'
-			// slowMo: DEBUG_TESTS ? 2000 : 0
+		browser = await playwright[testInfo.browser].launch({
+			headless: !testInfo.debugTests,
+			devtools: testInfo.debugTests && testInfo.browser === 'chromium'
+			// slowMo: testInfo.debugTests ? 2000 : 0
 		});
 	});
 

+ 0 - 0
test/smoke/webpack/webpack.html → test/smoke/webpack/index.html


+ 0 - 0
webpack-plugin/smoketest/index.js → test/smoke/webpack/index.js


+ 0 - 2
webpack-plugin/package.json

@@ -5,8 +5,6 @@
 	"main": "out/index.js",
 	"typings": "./out/index.d.ts",
 	"scripts": {
-		"package-for-smoketest": "node ./node_modules/webpack/bin/webpack.js --config smoketest/webpack.config.js --progress",
-		"smoketest-cross-origin": "node ./node_modules/webpack/bin/webpack.js --config smoketest/webpack-cross-origin.config.js --progress",
 		"watch": "tsc -w -p tsconfig.json",
 		"compile": "tsc -p tsconfig.json",
 		"import-editor": "node ./scripts/import-editor.js",

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

@@ -1,39 +0,0 @@
-const MonacoWebpackPlugin = require('../out/index.js');
-const path = require('path');
-
-const ASSET_PATH = 'http://localhost:8088/monaco-editor/test/smoke/webpack/out/';
-
-const REPO_ROOT = path.join(__dirname, '../../');
-
-module.exports = {
-	mode: 'development',
-	entry: './index.js',
-	context: __dirname,
-	output: {
-		path: path.resolve(REPO_ROOT, 'test/smoke/webpack/out'),
-		filename: 'app.js',
-		publicPath: ASSET_PATH
-	},
-	resolve: {
-		alias: {
-			'monaco-editor': path.resolve(REPO_ROOT, 'release')
-		}
-	},
-	module: {
-		rules: [
-			{
-				test: /\.css$/,
-				use: ['style-loader', 'css-loader']
-			},
-			{
-				test: /\.ttf$/,
-				use: ['file-loader']
-			}
-		]
-	},
-	plugins: [
-		new MonacoWebpackPlugin({
-			monacoEditorPath: path.resolve(REPO_ROOT, 'release')
-		})
-	]
-};

+ 0 - 36
webpack-plugin/smoketest/webpack.config.js

@@ -1,36 +0,0 @@
-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(REPO_ROOT, 'test/smoke/webpack/out'),
-		filename: 'app.js'
-	},
-	resolve: {
-		alias: {
-			'monaco-editor': path.resolve(REPO_ROOT, 'release')
-		}
-	},
-	module: {
-		rules: [
-			{
-				test: /\.css$/,
-				use: ['style-loader', 'css-loader']
-			},
-			{
-				test: /\.ttf$/,
-				use: ['file-loader']
-			}
-		]
-	},
-	plugins: [
-		new MonacoWebpackPlugin({
-			monacoEditorPath: path.resolve(REPO_ROOT, 'release')
-		})
-	]
-};

部分文件因为文件数量过多而无法显示