From 8b199cf9c3723ba2903cc79757f506a7f039ea4f Mon Sep 17 00:00:00 2001 From: Anatoly Date: Fri, 31 Aug 2018 13:44:23 +0300 Subject: [PATCH] migrating to typescript --- test/{Main.test.js => Main.test.ts} | 40 +++++++++++-------------- test/TestModules/SchemaProcessorTest.ts | 26 +++++++--------- test/TestModules/TestSchemaProcessor.ts | 2 +- 3 files changed, 29 insertions(+), 39 deletions(-) rename test/{Main.test.js => Main.test.ts} (59%) diff --git a/test/Main.test.js b/test/Main.test.ts similarity index 59% rename from test/Main.test.js rename to test/Main.test.ts index 1cab201..eb19bd7 100644 --- a/test/Main.test.js +++ b/test/Main.test.ts @@ -18,49 +18,45 @@ * * @author Anatoly Khaytovich */ -'use strict'; - -const test = require('tape'); -const TestSchemaProcessor = require('./TestModules/TestSchemaProcessor'); -const testSchema = require('./TestModules/SchemaProcessorTest'); -const testDataContent = require('./TestModules/DataContentTest'); -const testColumnTypes = require('./TestModules/ColumnTypesTest'); +import * as test from 'tape'; +import { EventEmitter } from 'events'; +import Conversion from '../src/Conversion'; +import TestSchemaProcessor from './TestModules/TestSchemaProcessor'; +import testSchema from './TestModules/SchemaProcessorTest'; +import testDataContent from './TestModules/DataContentTest'; +import testColumnTypes from './TestModules/ColumnTypesTest'; /** * Runs test suites. - * - * @param {TestSchemaProcessor} testSchemaProcessor - * - * @returns {Function} */ -const runTestSuites = testSchemaProcessor => { +function runTestSuites(testSchemaProcessor: TestSchemaProcessor): () => void { return () => { - test.onFinish(() => { - testSchemaProcessor.removeTestResources() - .then(() => process.exit()); + test.onFinish(async () => { + await testSchemaProcessor.removeTestResources(); + process.exit(); }); - test('Test schema should be created', tapeTestSchema => { + test('Test schema should be created', (tapeTestSchema: test.Test) => { testSchema(testSchemaProcessor, tapeTestSchema); }); - test('Test the data content', tapeTestDataContent => { + test('Test the data content', (tapeTestDataContent: test.Test) => { testDataContent(testSchemaProcessor, tapeTestDataContent); }); - test('Test column types', tapeTestColumnTypes => { + test('Test column types', (tapeTestColumnTypes: test.Test) => { testColumnTypes(testSchemaProcessor, tapeTestColumnTypes); }); }; -}; +} -const testSchemaProcessor = new TestSchemaProcessor(); +const testSchemaProcessor: TestSchemaProcessor = new TestSchemaProcessor(); testSchemaProcessor .initializeConversion() - .then(conversion => { + .then((conversion: Conversion) => { // Registers callback, that will be invoked when the test database arrangement will be completed. - conversion._eventEmitter.on(conversion._migrationCompletedEvent, runTestSuites(testSchemaProcessor)); + (conversion._eventEmitter).on(conversion._migrationCompletedEvent, runTestSuites(testSchemaProcessor)); // Continues the test database arrangement. return Promise.resolve(conversion); diff --git a/test/TestModules/SchemaProcessorTest.ts b/test/TestModules/SchemaProcessorTest.ts index 63c1d32..2e9e389 100644 --- a/test/TestModules/SchemaProcessorTest.ts +++ b/test/TestModules/SchemaProcessorTest.ts @@ -18,11 +18,12 @@ * * @author Anatoly Khaytovich */ -import { TestSchemaProcessor } from './TestSchemaProcessor'; +import TestSchemaProcessor from './TestSchemaProcessor'; import Conversion from '../../src/Conversion'; import DBAccess from '../../src/DBAccess'; import DBVendors from '../../src/DBVendors'; import DBAccessQueryResult from '../../src/DBAccessQueryResult'; +import { Test } from 'tape'; /** * Checks if the schema exists. @@ -44,21 +45,14 @@ async function hasSchemaCreated(testSchemaProcessor: TestSchemaProcessor): Promi } /** - * TODO: check @types/tape. - * Schema creation testing. - * - * @param {TestSchemaProcessor} testSchemaProcessor - * @param {Tape} tape - * - * @returns {undefined} + * Tests schema creation. */ -module.exports = (testSchemaProcessor, tape) => { - hasSchemaCreated(testSchemaProcessor).then(schemaExists => { - const numberOfPlannedAssertions = 1; - const autoTimeoutMs = 3 * 1000; // 3 seconds. +export default async function(testSchemaProcessor: TestSchemaProcessor, tape: Test): Promise { + const schemaExists: boolean = await hasSchemaCreated(testSchemaProcessor); + const numberOfPlannedAssertions: number = 1; + const autoTimeoutMs: number = 3 * 1000; // 3 seconds. - tape.plan(numberOfPlannedAssertions); - tape.timeoutAfter(autoTimeoutMs); - tape.equal(schemaExists, true); - }); + tape.plan(numberOfPlannedAssertions); + tape.timeoutAfter(autoTimeoutMs); + tape.equal(schemaExists, true); } diff --git a/test/TestModules/TestSchemaProcessor.ts b/test/TestModules/TestSchemaProcessor.ts index 7914713..7b8d29d 100644 --- a/test/TestModules/TestSchemaProcessor.ts +++ b/test/TestModules/TestSchemaProcessor.ts @@ -33,7 +33,7 @@ import { createStateLogsTable } from '../../src/MigrationStateManager'; import { createDataPoolTable, readDataPool } from '../../src/DataPoolManager'; import generateError from '../../src/ErrorGenerator'; -export class TestSchemaProcessor { +export default class TestSchemaProcessor { /** * Instance of class Main. */