Skip to content

Commit 88c5516

Browse files
Use jest for testing
1 parent 644a87d commit 88c5516

File tree

10 files changed

+4183
-1596
lines changed

10 files changed

+4183
-1596
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
# To get started with Dependabot version updates, you'll need to specify which
2-
# package ecosystems to update and where the package manifests are located.
3-
# Please see the documentation for all configuration options:
4-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5-
61
version: 2
72
updates:
83
- package-ecosystem: "github-actions"
94
directory: "/"
105
schedule:
11-
interval: "monthly"
6+
interval: "weekly"
7+
day: "sunday"
128
- package-ecosystem: "npm"
139
directory: "/generator"
1410
schedule:
15-
interval: "monthly"
11+
interval: "weekly"
12+
day: "sunday"
1613
- package-ecosystem: "npm"
1714
directory: "/tools"
1815
schedule:
19-
interval: "monthly"
16+
interval: "weekly"
17+
day: "sunday"

tools/jest.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
module.exports = {
4+
verbose: true,
5+
moduleFileExtensions: [
6+
"ts",
7+
"js"
8+
],
9+
transform: {
10+
'^.+\\.(ts|tsx)$': 'ts-jest'
11+
},
12+
testMatch: [
13+
'**/test/**/*.test.(ts)'
14+
],
15+
testEnvironment: 'node',
16+
};

tools/package-lock.json

Lines changed: 4129 additions & 1558 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@
99
},
1010
"scripts": {
1111
"build": "tsc -p .",
12-
"test": "mocha -r ts-node/register tests.ts",
12+
"test": "jest",
1313
"serve": "ts-node server.ts",
1414
"lint": "eslint . --ext ts",
1515
"lint:fix": "eslint . --ext ts --fix"
1616
},
1717
"devDependencies": {
18-
"@types/chai": "^4.3.14",
1918
"@types/express": "^4.17.21",
20-
"@types/mocha": "^10.0.6",
19+
"@types/jest": "^29.5.12",
2120
"@types/node": "^20.12.7",
2221
"@typescript-eslint/eslint-plugin": "^7.7.1",
2322
"@typescript-eslint/parser": "^7.7.1",
2423
"ajv": "^6.12.6",
25-
"chai": "^5.1.0",
2624
"eslint": "^8.56.0",
2725
"eslint-plugin-header": "^3.1.1",
2826
"express": "^4.19.2",
29-
"mocha": "^10.4.0",
30-
"mocha-junit-reporter": "^2.2.1",
27+
"jest": "^29.7.0",
28+
"ts-jest": "^29.1.2",
3129
"ts-node": "^10.9.2",
3230
"typescript": "^5.4.5",
3331
"vscode-json-languageservice": "^5.3.11",
File renamed without changes.
File renamed without changes.

tools/tests.ts renamed to tools/test/schemas.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
3-
import { expect } from 'chai';
43
import Ajv from 'ajv';
54
import * as url from 'url';
65
import path from 'path';
@@ -9,12 +8,11 @@ import { readFile } from 'fs/promises';
98
import { getLanguageService } from 'vscode-json-languageservice';
109
import { TextDocument } from 'vscode-languageserver-textdocument';
1110
import 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/');
1816
const armSchemasPrefix = /^https?:\/\/schema\.management\.azure\.com\/schemas\//
1917
const jsonSchemaDraft4Prefix = /^https?:\/\/json-schema\.org\/draft-04\/schema/
2018

@@ -140,60 +138,62 @@ const schemasToSkip = [
140138

141139
const schemaPaths = listSchemaPaths(schemasFolder).filter(path => schemasToSkip.indexOf(path) == -1);
142140
const templateTestPaths = listSchemaPaths(templateTestsFolder);
141+
const TIMEOUT_1_MINUTE = 60000;
143142

144143
describe('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

192194
describe('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
});
File renamed without changes.

tools/tsconfig.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
{
22
"compilerOptions": {
33
"skipLibCheck": true,
4+
"alwaysStrict": true,
5+
"forceConsistentCasingInFileNames": false,
46
"module": "commonjs",
57
"noEmitOnError": true,
8+
"noImplicitAny": true,
69
"noImplicitReturns": true,
10+
"noImplicitThis": true,
711
"sourceMap": true,
812
"declarationMap": true,
913
"strict": true,
1014
"declaration": true,
1115
"stripInternal": true,
1216
"noEmitHelpers": false,
1317
"target": "es2019",
14-
"types": ["node"],
18+
"types": ["node", "jest"],
1519
"esModuleInterop": true,
1620
"lib": ["es2020"],
1721
"newLine": "LF",
1822
"outDir": "out",
1923
"rootDir": ".",
2024
"resolveJsonModule": true
2125
},
22-
"exclude": ["out", "node_modules"]
26+
"exclude": ["out", "node_modules", "**/*.d.ts"]
2327
}

0 commit comments

Comments
 (0)