From d76b775d087cbbf1ebcd85be1fb1341202022efe Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Wed, 6 Sep 2023 13:01:56 +0200 Subject: [PATCH] Move typings tests to ts --- .../services/__tests__/worker-queue.test.ts | 4 +- .../src/types/__tests__/utils/string.test.js | 93 ---------------- .../src/types/__tests__/utils/string.test.ts | 102 ++++++++++++++++++ 3 files changed, 104 insertions(+), 95 deletions(-) delete mode 100644 packages/core/strapi/src/types/__tests__/utils/string.test.js create mode 100644 packages/core/strapi/src/types/__tests__/utils/string.test.ts diff --git a/packages/core/strapi/src/services/__tests__/worker-queue.test.ts b/packages/core/strapi/src/services/__tests__/worker-queue.test.ts index 1821397bf7..f30ff3897c 100644 --- a/packages/core/strapi/src/services/__tests__/worker-queue.test.ts +++ b/packages/core/strapi/src/services/__tests__/worker-queue.test.ts @@ -8,7 +8,7 @@ describe('WorkerQueue', () => { const q = new WorkerQueue({ logger: console.log.bind(console), concurrency: 1, - }); + } as any); q.subscribe(fn); q.enqueue(input); @@ -28,7 +28,7 @@ describe('WorkerQueue', () => { const q = new WorkerQueue({ logger: console.log.bind(console), concurrency: 1, - }); + } as any); q.subscribe(fn); q.enqueue(input); diff --git a/packages/core/strapi/src/types/__tests__/utils/string.test.js b/packages/core/strapi/src/types/__tests__/utils/string.test.js deleted file mode 100644 index d0f380dedb..0000000000 --- a/packages/core/strapi/src/types/__tests__/utils/string.test.js +++ /dev/null @@ -1,93 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const path_1 = __importDefault(require("path")); -const ts_zen_1 = require("ts-zen"); -const STRING_UTILS_DTS_PATH = path_1.default.join(__dirname, '..', 'definitions', 'utils', 'string.d.ts'); -/** - * @type {import('ts-zen').AssertTypeSelector} - */ -let assertType; -describe('Utils.String', () => { - beforeAll(() => { - assertType = (0, ts_zen_1.fromFile)(STRING_UTILS_DTS_PATH, { - compilerOptions: { strict: true }, - ignoreProjectOptions: true, - }); - }); - test('Dict', () => { - // TODO: Replace with isMappedType matcher when available - assertType('NumberDict').equals('{ [x: string]: number; }'); - assertType('StringDict').equals('{ [x: string]: string; }'); - assertType('BooleanDict').equals('{ [x: string]: boolean; }'); - }); - test('EndsWith', () => { - assertType('EndsWithCorrectNumber').isBooleanLiteral(true); - assertType('EndsWithIncorrectNumber').isBooleanLiteral(false); - assertType('EndsWithCorrectString').isBooleanLiteral(true); - assertType('EndsWithIncorrectString').isBooleanLiteral(false); - }); - test('StartsWith', () => { - assertType('StartsWithCorrectNumber').isBooleanLiteral(true); - assertType('StartsWithIncorrectNumber').isBooleanLiteral(false); - assertType('StartsWithCorrectString').isBooleanLiteral(true); - assertType('StartsWithIncorrectString').isBooleanLiteral(false); - }); - test('Includes', () => { - const template = (str) => [ts_zen_1.t.string(), String(str), ts_zen_1.t.string()]; - assertType('IncludesNumber').isTemplateLiteral(template(42)); - assertType('IncludesString').isTemplateLiteral(template('foo')); - assertType('IncludesBoolean').isUnion([ - ts_zen_1.t.templateLiteral(template(true)), - ts_zen_1.t.templateLiteral(template(false)), - ]); - assertType('IncludesBooleanLiteral').isTemplateLiteral(template(true)); - }); - test('NonEmpty', () => { - assertType('NonEmptyOnEmptyString').isNever(); - assertType('NonEmptyOnNonEmptyString').isStringLiteral('Hello World'); - }); - test('Prefix', () => { - assertType('PrefixEmptyString').isStringLiteral('Hello'); - assertType('PrefixString').isTemplateLiteral(['Hello ', ts_zen_1.t.string()]); - assertType('PrefixLiteralString').isStringLiteral('Hello World'); - assertType('PrefixLiteralStringUnion').isUnion([ - ts_zen_1.t.stringLiteral('Hello World'), - ts_zen_1.t.stringLiteral('Hello Everyone'), - ]); - assertType('PrefixLiteralStringWithUnion').isUnion([ - ts_zen_1.t.stringLiteral('Hello World'), - ts_zen_1.t.stringLiteral('Bonjour World'), - ts_zen_1.t.stringLiteral('Hola World'), - ]); - }); - test('Suffix', () => { - assertType('SuffixEmptyString').isStringLiteral('Hello'); - assertType('SuffixString').isTemplateLiteral([ts_zen_1.t.string(), '.']); - assertType('SuffixLiteralString').isStringLiteral('Hello World'); - assertType('SuffixLiteralStringUnion').isUnion([ - ts_zen_1.t.stringLiteral('Hello World'), - ts_zen_1.t.stringLiteral('Bonjour World'), - ts_zen_1.t.stringLiteral('Hola World'), - ]); - assertType('SuffixLiteralStringWithUnion').isUnion([ - ts_zen_1.t.stringLiteral('Hello World'), - ts_zen_1.t.stringLiteral('Hello Everyone'), - ]); - }); - test('Literal', () => { - assertType('Literal').isUnion([ts_zen_1.t.string(), ts_zen_1.t.number(), ts_zen_1.t.bigInt(), ts_zen_1.t.booleanLiteral()]); - }); - test('Split', () => { - assertType('SplitEmptyStringBySpace').isTuple([]); - assertType('SplitEmptyStringByEmptyString').isTuple([]); - assertType('SplitEmptyStringByString').isTuple([]); - assertType('SplitBySpace').isTuple(['Hello', 'World,', 'How', 'are', 'you?'].map(ts_zen_1.t.stringLiteral)); - assertType('SplitByEmptyString').isTuple(['H', 'e', 'l', 'l', 'o'].map(ts_zen_1.t.stringLiteral)); - // This will use any string character as a delimiter, thus removing 1/2 characters - assertType('SplitByString').isTuple(['H', 'l', 'o'].map(ts_zen_1.t.stringLiteral)); - }); -}); -//# sourceMappingURL=string.test.js.map \ No newline at end of file diff --git a/packages/core/strapi/src/types/__tests__/utils/string.test.ts b/packages/core/strapi/src/types/__tests__/utils/string.test.ts new file mode 100644 index 0000000000..369df4234b --- /dev/null +++ b/packages/core/strapi/src/types/__tests__/utils/string.test.ts @@ -0,0 +1,102 @@ +import path from 'path'; +import { fromFile, t } from 'ts-zen'; + +const STRING_UTILS_DTS_PATH = path.join(__dirname, '..', 'definitions', 'utils', 'string.d.ts'); + +/** + * @type {import('ts-zen').AssertTypeSelector} + */ +let assertType: any; + +describe('Utils.String', () => { + beforeAll(() => { + assertType = fromFile(STRING_UTILS_DTS_PATH, { + compilerOptions: { strict: true }, + ignoreProjectOptions: true, + }); + }); + + test('Dict', () => { + // TODO: Replace with isMappedType matcher when available + assertType('NumberDict').equals('{ [x: string]: number; }'); + assertType('StringDict').equals('{ [x: string]: string; }'); + assertType('BooleanDict').equals('{ [x: string]: boolean; }'); + }); + + test('EndsWith', () => { + assertType('EndsWithCorrectNumber').isBooleanLiteral(true); + assertType('EndsWithIncorrectNumber').isBooleanLiteral(false); + assertType('EndsWithCorrectString').isBooleanLiteral(true); + assertType('EndsWithIncorrectString').isBooleanLiteral(false); + }); + + test('StartsWith', () => { + assertType('StartsWithCorrectNumber').isBooleanLiteral(true); + assertType('StartsWithIncorrectNumber').isBooleanLiteral(false); + assertType('StartsWithCorrectString').isBooleanLiteral(true); + assertType('StartsWithIncorrectString').isBooleanLiteral(false); + }); + + test('Includes', () => { + const template = (str: string | number | boolean) => [t.string(), String(str), t.string()]; + + assertType('IncludesNumber').isTemplateLiteral(template(42)); + assertType('IncludesString').isTemplateLiteral(template('foo')); + assertType('IncludesBoolean').isUnion([ + t.templateLiteral(template(true)), + t.templateLiteral(template(false)), + ]); + assertType('IncludesBooleanLiteral').isTemplateLiteral(template(true)); + }); + + test('NonEmpty', () => { + assertType('NonEmptyOnEmptyString').isNever(); + assertType('NonEmptyOnNonEmptyString').isStringLiteral('Hello World'); + }); + + test('Prefix', () => { + assertType('PrefixEmptyString').isStringLiteral('Hello'); + assertType('PrefixString').isTemplateLiteral(['Hello ', t.string()]); + assertType('PrefixLiteralString').isStringLiteral('Hello World'); + assertType('PrefixLiteralStringUnion').isUnion([ + t.stringLiteral('Hello World'), + t.stringLiteral('Hello Everyone'), + ]); + assertType('PrefixLiteralStringWithUnion').isUnion([ + t.stringLiteral('Hello World'), + t.stringLiteral('Bonjour World'), + t.stringLiteral('Hola World'), + ]); + }); + + test('Suffix', () => { + assertType('SuffixEmptyString').isStringLiteral('Hello'); + assertType('SuffixString').isTemplateLiteral([t.string(), '.']); + assertType('SuffixLiteralString').isStringLiteral('Hello World'); + assertType('SuffixLiteralStringUnion').isUnion([ + t.stringLiteral('Hello World'), + t.stringLiteral('Bonjour World'), + t.stringLiteral('Hola World'), + ]); + assertType('SuffixLiteralStringWithUnion').isUnion([ + t.stringLiteral('Hello World'), + t.stringLiteral('Hello Everyone'), + ]); + }); + + test('Literal', () => { + assertType('Literal').isUnion([t.string(), t.number(), t.bigInt(), t.booleanLiteral()]); + }); + + test('Split', () => { + assertType('SplitEmptyStringBySpace').isTuple([]); + assertType('SplitEmptyStringByEmptyString').isTuple([]); + assertType('SplitEmptyStringByString').isTuple([]); + assertType('SplitBySpace').isTuple( + ['Hello', 'World,', 'How', 'are', 'you?'].map(t.stringLiteral) + ); + assertType('SplitByEmptyString').isTuple(['H', 'e', 'l', 'l', 'o'].map(t.stringLiteral)); + // This will use any string character as a delimiter, thus removing 1/2 characters + assertType('SplitByString').isTuple(['H', 'l', 'o'].map(t.stringLiteral)); + }); +});