migrating to typescript
This commit is contained in:
parent
1f81dda083
commit
8b199cf9c3
|
@ -18,49 +18,45 @@
|
||||||
*
|
*
|
||||||
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
||||||
*/
|
*/
|
||||||
'use strict';
|
import * as test from 'tape';
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
const test = require('tape');
|
import Conversion from '../src/Conversion';
|
||||||
const TestSchemaProcessor = require('./TestModules/TestSchemaProcessor');
|
import TestSchemaProcessor from './TestModules/TestSchemaProcessor';
|
||||||
const testSchema = require('./TestModules/SchemaProcessorTest');
|
import testSchema from './TestModules/SchemaProcessorTest';
|
||||||
const testDataContent = require('./TestModules/DataContentTest');
|
import testDataContent from './TestModules/DataContentTest';
|
||||||
const testColumnTypes = require('./TestModules/ColumnTypesTest');
|
import testColumnTypes from './TestModules/ColumnTypesTest';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs test suites.
|
* Runs test suites.
|
||||||
*
|
|
||||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
|
||||||
*
|
|
||||||
* @returns {Function}
|
|
||||||
*/
|
*/
|
||||||
const runTestSuites = testSchemaProcessor => {
|
function runTestSuites(testSchemaProcessor: TestSchemaProcessor): () => void {
|
||||||
return () => {
|
return () => {
|
||||||
test.onFinish(() => {
|
test.onFinish(async () => {
|
||||||
testSchemaProcessor.removeTestResources()
|
await testSchemaProcessor.removeTestResources();
|
||||||
.then(() => process.exit());
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test schema should be created', tapeTestSchema => {
|
test('Test schema should be created', (tapeTestSchema: test.Test) => {
|
||||||
testSchema(testSchemaProcessor, tapeTestSchema);
|
testSchema(testSchemaProcessor, tapeTestSchema);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test the data content', tapeTestDataContent => {
|
test('Test the data content', (tapeTestDataContent: test.Test) => {
|
||||||
testDataContent(testSchemaProcessor, tapeTestDataContent);
|
testDataContent(testSchemaProcessor, tapeTestDataContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test column types', tapeTestColumnTypes => {
|
test('Test column types', (tapeTestColumnTypes: test.Test) => {
|
||||||
testColumnTypes(testSchemaProcessor, tapeTestColumnTypes);
|
testColumnTypes(testSchemaProcessor, tapeTestColumnTypes);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
const testSchemaProcessor = new TestSchemaProcessor();
|
const testSchemaProcessor: TestSchemaProcessor = new TestSchemaProcessor();
|
||||||
|
|
||||||
testSchemaProcessor
|
testSchemaProcessor
|
||||||
.initializeConversion()
|
.initializeConversion()
|
||||||
.then(conversion => {
|
.then((conversion: Conversion) => {
|
||||||
// Registers callback, that will be invoked when the test database arrangement will be completed.
|
// Registers callback, that will be invoked when the test database arrangement will be completed.
|
||||||
conversion._eventEmitter.on(conversion._migrationCompletedEvent, runTestSuites(testSchemaProcessor));
|
(<EventEmitter>conversion._eventEmitter).on(conversion._migrationCompletedEvent, runTestSuites(testSchemaProcessor));
|
||||||
|
|
||||||
// Continues the test database arrangement.
|
// Continues the test database arrangement.
|
||||||
return Promise.resolve(conversion);
|
return Promise.resolve(conversion);
|
|
@ -18,11 +18,12 @@
|
||||||
*
|
*
|
||||||
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
||||||
*/
|
*/
|
||||||
import { TestSchemaProcessor } from './TestSchemaProcessor';
|
import TestSchemaProcessor from './TestSchemaProcessor';
|
||||||
import Conversion from '../../src/Conversion';
|
import Conversion from '../../src/Conversion';
|
||||||
import DBAccess from '../../src/DBAccess';
|
import DBAccess from '../../src/DBAccess';
|
||||||
import DBVendors from '../../src/DBVendors';
|
import DBVendors from '../../src/DBVendors';
|
||||||
import DBAccessQueryResult from '../../src/DBAccessQueryResult';
|
import DBAccessQueryResult from '../../src/DBAccessQueryResult';
|
||||||
|
import { Test } from 'tape';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the schema exists.
|
* Checks if the schema exists.
|
||||||
|
@ -44,21 +45,14 @@ async function hasSchemaCreated(testSchemaProcessor: TestSchemaProcessor): Promi
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: check @types/tape.
|
* Tests schema creation.
|
||||||
* Schema creation testing.
|
|
||||||
*
|
|
||||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
|
||||||
* @param {Tape} tape
|
|
||||||
*
|
|
||||||
* @returns {undefined}
|
|
||||||
*/
|
*/
|
||||||
module.exports = (testSchemaProcessor, tape) => {
|
export default async function(testSchemaProcessor: TestSchemaProcessor, tape: Test): Promise<void> {
|
||||||
hasSchemaCreated(testSchemaProcessor).then(schemaExists => {
|
const schemaExists: boolean = await hasSchemaCreated(testSchemaProcessor);
|
||||||
const numberOfPlannedAssertions = 1;
|
const numberOfPlannedAssertions: number = 1;
|
||||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
const autoTimeoutMs: number = 3 * 1000; // 3 seconds.
|
||||||
|
|
||||||
tape.plan(numberOfPlannedAssertions);
|
tape.plan(numberOfPlannedAssertions);
|
||||||
tape.timeoutAfter(autoTimeoutMs);
|
tape.timeoutAfter(autoTimeoutMs);
|
||||||
tape.equal(schemaExists, true);
|
tape.equal(schemaExists, true);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import { createStateLogsTable } from '../../src/MigrationStateManager';
|
||||||
import { createDataPoolTable, readDataPool } from '../../src/DataPoolManager';
|
import { createDataPoolTable, readDataPool } from '../../src/DataPoolManager';
|
||||||
import generateError from '../../src/ErrorGenerator';
|
import generateError from '../../src/ErrorGenerator';
|
||||||
|
|
||||||
export class TestSchemaProcessor {
|
export default class TestSchemaProcessor {
|
||||||
/**
|
/**
|
||||||
* Instance of class Main.
|
* Instance of class Main.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue