11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
3- import { expect } from 'chai' ;
43import Ajv from 'ajv' ;
54import * as url from 'url' ;
65import path from 'path' ;
@@ -9,12 +8,11 @@ import { readFile } from 'fs/promises';
98import { getLanguageService } from 'vscode-json-languageservice' ;
109import { TextDocument } from 'vscode-languageserver-textdocument' ;
1110import draft4MetaSchema from 'ajv/lib/refs/json-schema-draft-04.json' ;
12- import 'mocha' ;
13- import { findCycle } from './cycleCheck' ;
11+ import { findCycle } from '../src/cycleCheck' ;
1412
15- const schemasFolder = __dirname + ' /../schemas/';
16- const testSchemasFolder = __dirname + '/schemas/' ;
17- const templateTestsFolder = __dirname + ' /templateTests/';
13+ const schemasFolder = path . join ( __dirname , '.. /../schemas/') ;
14+ const testSchemasFolder = path . join ( __dirname , '../testSchemas/' ) ;
15+ const templateTestsFolder = path . join ( __dirname , '.. /templateTests/') ;
1816const armSchemasPrefix = / ^ h t t p s ? : \/ \/ s c h e m a \. m a n a g e m e n t \. a z u r e \. c o m \/ s c h e m a s \/ /
1917const jsonSchemaDraft4Prefix = / ^ h t t p s ? : \/ \/ j s o n - s c h e m a \. o r g \/ d r a f t - 0 4 \/ s c h e m a /
2018
@@ -140,60 +138,62 @@ const schemasToSkip = [
140138
141139const schemaPaths = listSchemaPaths ( schemasFolder ) . filter ( path => schemasToSkip . indexOf ( path ) == - 1 ) ;
142140const templateTestPaths = listSchemaPaths ( templateTestsFolder ) ;
141+ const TIMEOUT_1_MINUTE = 60000 ;
143142
144143describe ( 'Validate individual resource schemas' , ( ) => {
145144 it ( `can be parsed with JSON.parse` , async function ( ) {
146- this . timeout ( 60000 ) ;
147145 for ( const schemaPath of schemaPaths ) {
148146 const schema = await loadRawSchema ( schemaPath ) ;
149147
150- expect ( ( ) => JSON . parse ( schema ) , `Parsing ${ schemaPath } ` ) . not . to . throw ( ) ;
148+ expect ( ( ) => JSON . parse ( schema ) ) . not . toThrow ( ) ;
151149 }
152- } ) ;
150+ } , TIMEOUT_1_MINUTE ) ;
153151
154152 for ( const metaSchemaPath of metaSchemaPaths ) {
155153 it ( `validates against '${ metaSchemaPath } '` , async function ( ) {
156- this . timeout ( 60000 ) ;
157154 for ( const schemaPath of schemaPaths ) {
158155 const schema = await loadSchema ( schemaPath ) ;
159156 const metaSchema = await loadSchema ( metaSchemaPath ) ;
160157
161158 const validate = await ajvInstance . compileAsync ( metaSchema ) ;
162159 const result = await validate ( schema ) ;
163160
164- expect ( result , `Validating ${ schemaPath } failed with errors ${ JSON . stringify ( validate . errors , null , 2 ) } ` ) . to . be . true ;
161+ if ( ! result ) {
162+ console . error ( `Validating ${ schemaPath } failed with errors ${ JSON . stringify ( validate . errors , null , 2 ) } ` ) ;
163+ }
164+ expect ( result ) . toBeTruthy ( ) ;
165165 }
166- } ) ;
166+ } , TIMEOUT_1_MINUTE ) ;
167167 }
168168
169169 it ( `can be compiled` , async function ( ) {
170- this . timeout ( 60000 ) ;
171170 for ( const schemaPath of schemaPaths ) {
172171 const schema = await loadSchema ( schemaPath ) ;
173172
174- expect ( ( ) => ajvInstance . compile ( schema ) , `Compiling ${ schemaPath } ` ) . not . to . throw ( ) ;
173+ expect ( ( ) => ajvInstance . compile ( schema ) ) . not . toThrow ( ) ;
175174 }
176- } ) ;
175+ } , TIMEOUT_1_MINUTE ) ;
177176
178177 it ( `does not contain any cycles` , async function ( ) {
179178
180179 for ( const schemaPath of schemaPaths ) {
181180 if ( ! schemasToSkipForCyclicValidation . has ( schemaPath ) ) {
182- this . timeout ( 60000 ) ;
183181 const schema = await loadSchema ( schemaPath ) ;
184182
185183 const cycle = findCycle ( schema ) ;
186- expect ( cycle , `Found ${ schemaPath } cycle ${ cycle ?. join ( ' -> ' ) } ` ) . to . be . undefined ;
184+
185+ if ( cycle ) {
186+ console . error ( `Found ${ schemaPath } cycle ${ cycle ?. join ( ' -> ' ) } ` ) ;
187+ }
188+ expect ( cycle ) . toBeUndefined ( ) ;
187189 }
188190 }
189- } ) ;
191+ } , TIMEOUT_1_MINUTE ) ;
190192} ) ;
191193
192194describe ( 'Validate test templates against VSCode language service' , ( ) => {
193195 for ( const templateTestFile of templateTestPaths ) {
194196 it ( `running schema validation on '${ templateTestFile } '` , async function ( ) {
195- this . timeout ( 60000 ) ;
196-
197197 const service = getLanguageService ( {
198198 schemaRequestService : loadRawSchema ,
199199 workspaceContext : {
@@ -206,7 +206,7 @@ describe('Validate test templates against VSCode language service', () => {
206206 const jsonDocument = service . parseJSONDocument ( textDocument ) ;
207207
208208 const result = await service . doValidation ( textDocument , jsonDocument ) ;
209- expect ( result ) . to . deep . equal ( [ ] ) ;
210- } ) ;
209+ expect ( result ) . toEqual ( [ ] ) ;
210+ } , TIMEOUT_1_MINUTE ) ;
211211 }
212212} ) ;
0 commit comments