Skip to content

Commit

Permalink
Remove vitest.workspace config. Fix tests and improve default and deb…
Browse files Browse the repository at this point in the history
…ug test config
  • Loading branch information
kaisalmen committed Sep 27, 2024
1 parent e16dd08 commit 1f346a2
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
],
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
},
"vitest.disableWorkspaceWarning": true
}
4 changes: 2 additions & 2 deletions packages/wrapper/src/languageClientWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ export class LanguageClientWrapper {
if (!this.worker) {
if (lccOptions.$type === 'WorkerConfig') {
const workerConfig = lccOptions as WorkerConfigOptionsParams;
this.worker = new Worker(new URL(workerConfig.url, import.meta.url).href, {
this.worker = new Worker(workerConfig.url.href, {
type: workerConfig.type,
name: workerConfig.workerName
});

this.worker.onerror = (ev) => {
const languageClientError: LanguageClientError = {
message: `languageClientWrapper (${this.name}): Illegal worker configuration detected. Potentially the url is wrong.`,
message: `languageClientWrapper (${this.name}): Illegal worker configuration detected.`,
error: ev.error ?? 'No error was provided.'
};
reject(languageClientError);
Expand Down
4 changes: 2 additions & 2 deletions packages/wrapper/test/languageClientWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Test LanguageClientWrapper', () => {
connection: {
options: {
$type: 'WorkerConfig',
url: new URL('http://localhost:20101'),
url: new URL(`${import.meta.url.split('@fs')[0]}/packages/wrapper/test/worker/langium-server.ts`),
type: 'classic'
}
}
Expand All @@ -158,7 +158,7 @@ describe('Test LanguageClientWrapper', () => {
expect(languageClientWrapper).toBeDefined();

await expect(languageClientWrapper!.start()).rejects.toEqual({
message: 'languageClientWrapper (unnamed): Illegal worker configuration detected. Potentially the url is wrong.',
message: 'languageClientWrapper (unnamed): Illegal worker configuration detected.',
error: 'No error was provided.'
});
});
Expand Down
119 changes: 59 additions & 60 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,70 @@ import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin';
import vsixPlugin from '@codingame/monaco-vscode-rollup-vsix-plugin';
import react from '@vitejs/plugin-react';

export default defineConfig(({ command }) => {
console.log(`Running: ${command}`);
return {
build: {
target: 'esnext',
rollupOptions: {
input: {
index: path.resolve(__dirname, 'index.html'),
// bare monaco-languageclient
bare: path.resolve(__dirname, 'packages/examples/bare.html'),
export const definedViteConfig = defineConfig({
build: {
target: 'esnext',
rollupOptions: {
input: {
index: path.resolve(__dirname, 'index.html'),
// bare monaco-languageclient
bare: path.resolve(__dirname, 'packages/examples/bare.html'),

// monaco-editor-wrapper
// json
wrapperWebSocket: path.resolve(__dirname, 'packages/examples/json.html'),
browser: path.resolve(__dirname, 'packages/examples/browser.html'),
// langium
wrapperStatemachine: path.resolve(__dirname, 'packages/examples/statemachine.html'),
wrapperLangium: path.resolve(__dirname, 'packages/examples/langium.html'),
// python
python: path.resolve(__dirname, 'packages/examples/python.html'),
// grrovy
groovy: path.resolve(__dirname, 'packages/examples/groovy.html'),
// monaco-editor-wrapper
// json
wrapperWebSocket: path.resolve(__dirname, 'packages/examples/json.html'),
browser: path.resolve(__dirname, 'packages/examples/browser.html'),
// langium
wrapperStatemachine: path.resolve(__dirname, 'packages/examples/statemachine.html'),
wrapperLangium: path.resolve(__dirname, 'packages/examples/langium.html'),
// python
python: path.resolve(__dirname, 'packages/examples/python.html'),
// grrovy
groovy: path.resolve(__dirname, 'packages/examples/groovy.html'),

// json & python
twoLangaugeClients: path.resolve(__dirname, 'packages/examples/two_langauge_clients.html'),
// json & python
twoLangaugeClients: path.resolve(__dirname, 'packages/examples/two_langauge_clients.html'),

// monaco-editor-react
// langium
reactStatemachine: path.resolve(__dirname, 'packages/examples/react_statemachine.html'),
// python
reactPython: path.resolve(__dirname, 'packages/examples/react_python.html'),
// monaco-editor-react
// langium
reactStatemachine: path.resolve(__dirname, 'packages/examples/react_statemachine.html'),
// python
reactPython: path.resolve(__dirname, 'packages/examples/react_python.html'),

// other examples
wrapperTs: path.resolve(__dirname, 'packages/examples/ts.html')
}
// other examples
wrapperTs: path.resolve(__dirname, 'packages/examples/ts.html')
}
},
resolve: {
// not needed here, see https://github.com/TypeFox/monaco-languageclient#vite-dev-server-troubleshooting
// dedupe: ['vscode']
},
server: {
origin: 'http://localhost:20001',
port: 20001
},
optimizeDeps: {
esbuildOptions: {
plugins: [
importMetaUrlPlugin
]
},
include: [
'vscode-textmate',
'vscode-oniguruma'
}
},
resolve: {
// not needed here, see https://github.com/TypeFox/monaco-languageclient#vite-dev-server-troubleshooting
// dedupe: ['vscode']
},
server: {
origin: 'http://localhost:20001',
port: 20001
},
optimizeDeps: {
esbuildOptions: {
plugins: [
importMetaUrlPlugin
]
},
plugins: [
vsixPlugin(),
react(),
],
define: {
rootDirectory: JSON.stringify(__dirname)
},
worker: {
format: 'es'
}
};
include: [
'vscode-textmate',
'vscode-oniguruma'
]
},
plugins: [
vsixPlugin(),
react(),
],
define: {
rootDirectory: JSON.stringify(__dirname)
},
worker: {
format: 'es'
}
});

export default definedViteConfig;
18 changes: 6 additions & 12 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import { defineConfig, defineConfig as vitestDefineConfig, mergeConfig, UserConfig } from 'vitest/config';
import viteConfig from './vite.config.js';
import { mergeConfig } from 'vite';
import { defineConfig as defineVitestConfig } from 'vitest/config';
import definedViteConfig from './vite.config.js';

export const vitestConfig: UserConfig = {
export const vitestBaseConfig = {
test: {
testTimeout: 10000,
pool: 'threads',
Expand Down Expand Up @@ -38,14 +39,7 @@ export const vitestConfig: UserConfig = {
}
};

export default defineConfig(configEnv => {
const definedVitestConfig = defineVitestConfig(vitestBaseConfig);

console.log('vitestConfig:', vitestConfig);
export default mergeConfig(definedVitestConfig, definedViteConfig);

const mergedConfig = mergeConfig(
viteConfig(configEnv),
vitestDefineConfig(vitestConfig)
);

return mergedConfig;
});
26 changes: 9 additions & 17 deletions vitest.debug.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import { defineConfig, mergeConfig } from 'vitest/config';
import viteConfig from './vite.config.js';
import { vitestConfig } from './vitest.config.js';
import { mergeConfig } from 'vite';
import { defineConfig as defineVitestConfig } from 'vitest/config';
import { definedViteConfig } from './vite.config.js';
import { vitestBaseConfig } from './vitest.config.js';

export default defineConfig(configEnv => {
const vitestDebugConfig = vitestBaseConfig;
vitestDebugConfig.test.browser.name = 'chromium';
vitestDebugConfig.test.browser.provider = 'playwright';

const vitestDebugConfig = vitestConfig;
vitestDebugConfig.test!.browser!.name = 'chromium';
vitestDebugConfig.test!.browser!.provider = 'playwright';
const definedVitestDebugConfig = defineVitestConfig(vitestDebugConfig);

console.log('vitestDebugConfig:', vitestDebugConfig);

const mergedConfig = mergeConfig(
viteConfig(configEnv),
defineConfig(vitestDebugConfig)
);

return mergedConfig;

});
export default mergeConfig(definedVitestDebugConfig, definedViteConfig);
11 changes: 0 additions & 11 deletions vitest.workspace.ts

This file was deleted.

0 comments on commit 1f346a2

Please sign in to comment.