mirror of
https://github.com/chenasraf/DefinitelyTyped-tools.git
synced 2026-05-17 17:48:07 +00:00
Port dtslint tests to jest, re-root dts-critic tests (#364)
* Port dtslint tests to jest, re-root dts-critic tests dts-critic tests need to be run from DefinitelyTyped-tools/ root now, which also changes a couple of the assertions. * build dtslint before running tests * remove @types/jest devDep from dts-critic * add dts-critic/dtslint to root build * better name for dtslint tests
This commit is contained in:
committed by
GitHub
parent
5f0b0cf639
commit
23c7bacc24
@@ -2,7 +2,7 @@ module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
modulePathIgnorePatterns: ["packages\\/publisher\\/output"],
|
||||
testMatch: ["<rootDir>/packages/*/test/**/*.test.ts"],
|
||||
testMatch: ["<rootDir>/packages/*/test/**/*.test.ts", "<rootDir>/packages/dts-critic/index.test.ts"],
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.test.json",
|
||||
|
||||
@@ -26,13 +26,13 @@ suite("findDtsName", {
|
||||
expect(findDtsName("jquery/index.d.ts")).toBe("jquery");
|
||||
},
|
||||
currentDirectory() {
|
||||
expect(findDtsName("index.d.ts")).toBe("dts-critic");
|
||||
expect(findDtsName("index.d.ts")).toBe("DefinitelyTyped-tools");
|
||||
},
|
||||
relativeCurrentDirectory() {
|
||||
expect(findDtsName("./index.d.ts")).toBe("dts-critic");
|
||||
expect(findDtsName("./index.d.ts")).toBe("DefinitelyTyped-tools");
|
||||
},
|
||||
emptyDirectory() {
|
||||
expect(findDtsName("")).toBe("dts-critic");
|
||||
expect(findDtsName("")).toBe("DefinitelyTyped-tools");
|
||||
}
|
||||
});
|
||||
suite("getNpmInfo", {
|
||||
@@ -76,16 +76,22 @@ const allErrors: Map<ExportErrorKind, true> = new Map([
|
||||
[ErrorKind.JsPropertyNotInDts, true]
|
||||
]);
|
||||
|
||||
function testsource(filename: string) {
|
||||
return __dirname + "/testsource/" + filename;
|
||||
}
|
||||
|
||||
suite("checkSource", {
|
||||
noErrors() {
|
||||
expect(checkSource("noErrors", "testsource/noErrors.d.ts", "testsource/noErrors.js", allErrors, false)).toEqual([]);
|
||||
expect(checkSource("noErrors", testsource("noErrors.d.ts"), testsource("noErrors.js"), allErrors, false)).toEqual(
|
||||
[]
|
||||
);
|
||||
},
|
||||
missingJsProperty() {
|
||||
expect(
|
||||
checkSource(
|
||||
"missingJsProperty",
|
||||
"testsource/missingJsProperty.d.ts",
|
||||
"testsource/missingJsProperty.js",
|
||||
testsource("missingJsProperty.d.ts"),
|
||||
testsource("missingJsProperty.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -103,8 +109,8 @@ The JavaScript module exports a property named 'foo', which is missing from the
|
||||
expect(
|
||||
checkSource(
|
||||
"missingJsProperty",
|
||||
"testsource/webpackPropertyNames.d.ts",
|
||||
"testsource/webpackPropertyNames.js",
|
||||
testsource("webpackPropertyNames.d.ts"),
|
||||
testsource("webpackPropertyNames.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -114,8 +120,8 @@ The JavaScript module exports a property named 'foo', which is missing from the
|
||||
expect(
|
||||
checkSource(
|
||||
"missingDtsProperty",
|
||||
"testsource/missingDtsProperty.d.ts",
|
||||
"testsource/missingDtsProperty.js",
|
||||
testsource("missingDtsProperty.d.ts"),
|
||||
testsource("missingDtsProperty.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -135,7 +141,13 @@ The declaration module exports a property named 'foo', which is missing from the
|
||||
},
|
||||
missingDefaultExport() {
|
||||
expect(
|
||||
checkSource("missingDefault", "testsource/missingDefault.d.ts", "testsource/missingDefault.js", allErrors, false)
|
||||
checkSource(
|
||||
"missingDefault",
|
||||
testsource("missingDefault.d.ts"),
|
||||
testsource("missingDefault.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
@@ -157,8 +169,8 @@ To learn more about 'export =' syntax, see https://www.typescriptlang.org/docs/h
|
||||
expect(
|
||||
checkSource(
|
||||
"missingJsSignatureExportEquals",
|
||||
"testsource/missingJsSignatureExportEquals.d.ts",
|
||||
"testsource/missingJsSignatureExportEquals.js",
|
||||
testsource("missingJsSignatureExportEquals.d.ts"),
|
||||
testsource("missingJsSignatureExportEquals.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -176,8 +188,8 @@ The JavaScript module can be called or constructed, but the declaration module c
|
||||
expect(
|
||||
checkSource(
|
||||
"missingJsSignatureNoExportEquals",
|
||||
"testsource/missingJsSignatureNoExportEquals.d.ts",
|
||||
"testsource/missingJsSignatureNoExportEquals.js",
|
||||
testsource("missingJsSignatureNoExportEquals.d.ts"),
|
||||
testsource("missingJsSignatureNoExportEquals.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -198,8 +210,8 @@ To learn more about 'export =' syntax, see https://www.typescriptlang.org/docs/h
|
||||
expect(
|
||||
checkSource(
|
||||
"missingDtsSignature",
|
||||
"testsource/missingDtsSignature.d.ts",
|
||||
"testsource/missingDtsSignature.js",
|
||||
testsource("missingDtsSignature.d.ts"),
|
||||
testsource("missingDtsSignature.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -217,8 +229,8 @@ The declaration module can be called or constructed, but the JavaScript module c
|
||||
expect(
|
||||
checkSource(
|
||||
"missingExportEquals",
|
||||
"testsource/missingExportEquals.d.ts",
|
||||
"testsource/missingExportEquals.js",
|
||||
testsource("missingExportEquals.d.ts"),
|
||||
testsource("missingExportEquals.js"),
|
||||
allErrors,
|
||||
false
|
||||
)
|
||||
@@ -237,10 +249,10 @@ To learn more about 'export =' syntax, see https://www.typescriptlang.org/docs/h
|
||||
});
|
||||
suite("dtsCritic", {
|
||||
noErrors() {
|
||||
expect(dtsCritic("testsource/dts-critic.d.ts", "testsource/dts-critic.js")).toEqual([]);
|
||||
expect(dtsCritic(testsource("dts-critic.d.ts"), testsource("dts-critic.js"))).toEqual([]);
|
||||
},
|
||||
noMatchingNpmPackage() {
|
||||
expect(dtsCritic("testsource/parseltongue.d.ts")).toEqual([
|
||||
expect(dtsCritic(testsource("parseltongue.d.ts"))).toEqual([
|
||||
{
|
||||
kind: ErrorKind.NoMatchingNpmPackage,
|
||||
message: `Declaration file must have a matching npm package.
|
||||
@@ -256,7 +268,7 @@ Add -browser to the end of your name to make sure it doesn't conflict with exist
|
||||
]);
|
||||
},
|
||||
noMatchingNpmVersion() {
|
||||
expect(dtsCritic("testsource/typescript.d.ts")).toEqual([
|
||||
expect(dtsCritic(testsource("typescript.d.ts"))).toEqual([
|
||||
{
|
||||
kind: ErrorKind.NoMatchingNpmVersion,
|
||||
message: expect.stringContaining(`The types for 'typescript' must match a version that exists on npm.
|
||||
@@ -265,7 +277,7 @@ You should copy the major and minor version from the package on npm.`)
|
||||
]);
|
||||
},
|
||||
nonNpmHasMatchingPackage() {
|
||||
expect(dtsCritic("testsource/tslib.d.ts")).toEqual([
|
||||
expect(dtsCritic(testsource("tslib.d.ts"))).toEqual([
|
||||
{
|
||||
kind: ErrorKind.NonNpmHasMatchingPackage,
|
||||
message: `The non-npm package 'tslib' conflicts with the existing npm package 'tslib'.
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
module.exports = {
|
||||
rootDir: "dist",
|
||||
moduleFileExtensions: [
|
||||
"js",
|
||||
"jsx",
|
||||
"json",
|
||||
"node"
|
||||
],
|
||||
};
|
||||
@@ -19,7 +19,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/command-exists": "^1.2.0",
|
||||
"@types/jest": "^24.0.0",
|
||||
"@types/node": "~10.17.0",
|
||||
"@types/rimraf": "^3.0.0",
|
||||
"@types/semver": "^6.0.1",
|
||||
@@ -32,10 +31,9 @@
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "npm run build && jest",
|
||||
"build": "tsc -b .",
|
||||
"dt": "node dist/dt.js",
|
||||
"prepublishOnly": "npm run build && npm run test"
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
"watch": "tsc --watch",
|
||||
"build": "tsc -b .",
|
||||
"lint": "eslint --ext ts src",
|
||||
"test": "npm run build && node test/test.js",
|
||||
"prepublishOnly": "npm run build && npm run test && npm run lint"
|
||||
"prepublishOnly": "npm run build && npm run lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@definitelytyped/dts-critic": "^0.0.99",
|
||||
|
||||
42
packages/dtslint/test/index.test.ts
Normal file
42
packages/dtslint/test/index.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/// <reference types="jest" />
|
||||
import { join } from "path";
|
||||
import { consoleTestResultHandler, runTest } from "tslint/lib/test";
|
||||
import { existsSync, readdirSync } from "fs";
|
||||
|
||||
const testDir = __dirname;
|
||||
|
||||
class Logger {
|
||||
logmsg = "";
|
||||
errormsg = "";
|
||||
log(message: string): void {
|
||||
this.logmsg += message;
|
||||
}
|
||||
error(message: string): void {
|
||||
this.errormsg += message;
|
||||
}
|
||||
}
|
||||
|
||||
function testSingle(testDirectory: string) {
|
||||
test(testDirectory, () => {
|
||||
const logger = new Logger();
|
||||
const result = consoleTestResultHandler(runTest(testDirectory), logger);
|
||||
if (!result) {
|
||||
console.log(logger.logmsg + logger.errormsg);
|
||||
}
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
}
|
||||
|
||||
describe("dtslint", () => {
|
||||
const tests = readdirSync(testDir).filter(x => x !== "index.test.ts");
|
||||
for (const testName of tests) {
|
||||
const testDirectory = join(testDir, testName);
|
||||
if (existsSync(join(testDirectory, "tslint.json"))) {
|
||||
testSingle(testDirectory);
|
||||
} else {
|
||||
for (const subTestName of readdirSync(testDirectory)) {
|
||||
testSingle(join(testDirectory, subTestName));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
#! /usr/bin/env node
|
||||
const { join: joinPaths } = require("path");
|
||||
const { consoleTestResultHandler, runTest } = require("tslint/lib/test");
|
||||
const { existsSync, readdirSync } = require("fs");
|
||||
|
||||
const testDir = __dirname;
|
||||
|
||||
const tests = readdirSync(testDir).filter(x => x !== "test.js");
|
||||
|
||||
for (const testName of tests) {
|
||||
const testDirectory = joinPaths(testDir, testName);
|
||||
if (existsSync(joinPaths(testDirectory, "tslint.json"))) {
|
||||
testSingle(testDirectory);
|
||||
} else {
|
||||
for (const subTestName of readdirSync(testDirectory)) {
|
||||
testSingle(joinPaths(testDirectory, subTestName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testSingle(testDirectory) {
|
||||
const result = runTest(testDirectory);
|
||||
if (!consoleTestResultHandler(result, /*logger*/ console)) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "packages/definitions-parser" },
|
||||
{ "path": "packages/dts-critic" },
|
||||
{ "path": "packages/dtslint" },
|
||||
{ "path": "packages/dtslint-runner" },
|
||||
{ "path": "packages/header-parser" },
|
||||
{ "path": "packages/perf" },
|
||||
|
||||
Reference in New Issue
Block a user