@@ -2,14 +2,15 @@ const requirejs = require('requirejs');
22const jsdom = require ( 'jsdom' ) ;
33const glob = require ( 'fast-glob' ) ;
44const path = require ( 'path' ) ;
5+ const Mocha = require ( 'mocha' ) ;
56
67requirejs . config ( {
7- baseUrl : '' ,
8+ baseUrl : path . join ( __dirname , '../' ) ,
89 paths : {
10+ vs : 'node_modules/monaco-editor/dev/vs' ,
911 'vs/css' : 'test/css.mock' ,
1012 'vs/nls' : 'test/nls.mock' ,
11- 'out/amd/fillers/monaco-editor-core' : 'out/amd/fillers/monaco-editor-core-amd' ,
12- vs : 'node_modules/monaco-editor/dev/vs'
13+ 'out/amd/fillers/monaco-editor-core' : 'out/amd/fillers/monaco-editor-core-amd'
1314 } ,
1415 nodeRequire : require
1516} ) ;
@@ -24,6 +25,9 @@ global.document.queryCommandSupported = function () {
2425} ;
2526global . UIEvent = tmp . window . UIEvent ;
2627global . define = requirejs . define ;
28+
29+ // 添加完整的DOM环境支持
30+ global . Element = tmp . window . Element ;
2731global . window = {
2832 location : { } ,
2933 navigator : tmp . window . navigator ,
@@ -32,8 +36,18 @@ global.window = {
3236 matches : false ,
3337 addEventListener : function ( ) { }
3438 } ;
35- }
39+ } ,
40+ setInterval : setInterval ,
41+ clearInterval : clearInterval ,
42+ setTimeout : setTimeout ,
43+ clearTimeout : clearTimeout ,
44+ document : tmp . window . document ,
45+ Element : tmp . window . Element
3646} ;
47+ if ( ! document . body ) {
48+ const body = document . createElement ( 'body' ) ;
49+ document . appendChild ( body ) ;
50+ }
3751
3852requirejs (
3953 [ './test/setup' ] ,
@@ -52,10 +66,37 @@ requirejs(
5266 requirejs (
5367 files . map ( ( f ) => f . replace ( / \. j s $ / , '' ) ) ,
5468 function ( ) {
55- run ( ) ; // We can launch the tests!
69+ // 初始化Mocha
70+ const mocha = new Mocha ( {
71+ ui : 'bdd' ,
72+ reporter : 'spec' ,
73+ timeout : 5000
74+ } ) ;
75+
76+ // 手动添加测试到Mocha的suite
77+ const Suite = require ( 'mocha/lib/suite' ) ;
78+ const Test = require ( 'mocha/lib/test' ) ;
79+
80+ // 创建一个根suite
81+ const rootSuite = new Suite ( 'Root Suite' ) ;
82+ mocha . suite . addSuite ( rootSuite ) ;
83+
84+ // 添加存储的测试
85+ if ( global . _pendingTests && global . _pendingTests . length > 0 ) {
86+ global . _pendingTests . forEach ( function ( test ) {
87+ const mochaTest = new Test ( test . name , test . fn ) ;
88+ rootSuite . addTest ( mochaTest ) ;
89+ } ) ;
90+ }
91+
92+ // 运行测试
93+ mocha . run ( function ( failures ) {
94+ process . exit ( failures ? 1 : 0 ) ;
95+ } ) ;
5696 } ,
5797 function ( err ) {
58- console . log ( err ) ;
98+ console . log ( 'Error loading test files:' , err ) ;
99+ process . exit ( 1 ) ;
59100 }
60101 ) ;
61102 } ,
0 commit comments