Skip to content

Commit

Permalink
fix(tests): fiddle with rollup chunks until tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Sep 8, 2019
1 parent b018579 commit 3d9ea24
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
stages:
# @retain
- status-pre
- build
- image
Expand Down Expand Up @@ -177,8 +178,10 @@ sonar-success:
stage: status-post
when: on_success
dependencies:
# @retain
- build-node
script:
# @retain
- make node_modules
- sonar-scanner
-Dsonar.projectKey=ssube_isolex
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test: test-cover

test-check: ## run mocha unit tests with coverage reports
#$(NODE_BIN)/nyc $(COVER_OPTS)
$(NODE_BIN)/mocha $(MOCHA_OPTS) $(TARGET_PATH)/test.js
ISOLEX_HOME=$(ROOT_PATH)/docs $(NODE_BIN)/mocha $(MOCHA_OPTS) $(TARGET_PATH)/test.js

test-cover: ## run mocha unit tests with coverage reports
test-cover: test-check
Expand Down
16 changes: 13 additions & 3 deletions config/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import multiEntry from 'rollup-plugin-multi-entry';
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import yaml from 'rollup-plugin-yaml';

const debug = process.env['DEBUG'] === 'TRUE';
const passStub = 'require("pass-stub")'
Expand All @@ -13,6 +14,14 @@ const metadata = require('../package.json');
const bundle = {
external: [
'async_hooks',
'aws-sdk',
'chai',
'discord.js',
'ecc-jsbn',
'shelljs',
'snekfetch',
'sshpk',
'xmlbuilder',
],
input: {
include: [
Expand All @@ -30,15 +39,15 @@ const bundle = {
return 'vendor';
}

if (id.match(/commonjs/i) || id.match(/rollup/i) || id.includes('noicejs') || id.includes('pass-stub')) {
if (id.match(/commonjs-external/i) || id.match(/commonjsHelpers/) || id.includes('noicejs') || id.includes('pass-stub')) {
if (debug) {
console.log('==vendor', id);
}

return 'vendor';
}

if (id.includes('/src/')) {
if (id.includes('/isolex/src/') && !id.match(/src\/index.ts$/)) {
if (debug) {
console.log('==main', id);
}
Expand Down Expand Up @@ -68,6 +77,7 @@ const bundle = {
plugins: [
multiEntry(),
json(),
yaml(),
externals({
builtins: true,
deps: true,
Expand Down Expand Up @@ -120,7 +130,7 @@ const bundle = {
namedExports: {
'node_modules/chai/index.js': [
'expect',
'use',
//'use',
],
'node_modules/cron/lib/cron.js': [
'CronJob',
Expand Down
1 change: 1 addition & 0 deletions docs/.isolex.yml
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"private": false,
"dependencies": {
"jsonpath": "1.0.2",
"sqlite3": "4.0.9"
"sqlite3": "4.0.9",
"typeorm": "0.2.18"
},
"devDependencies": {
"@kubernetes/client-node": "0.10.2",
Expand Down Expand Up @@ -85,6 +86,7 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-typescript2": "^0.24.0",
"rollup-plugin-yaml": "^1.1.0",
"rxjs": "6.5.2",
"rxjs-tslint-rules": "4.24.3",
"shiro-trie": "0.4.8",
Expand All @@ -100,7 +102,6 @@
"tslint-microsoft-contrib": "6.2.0",
"tslint-sonarts": "1.9.0",
"typedoc": "0.14.2",
"typeorm": "0.2.18",
"typescript": "3.5.3",
"utf-8-validate": "5.0.2",
"uuid": "3.3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseOptions, Inject, Logger, MissingValueError } from 'noicejs';
import { Registry } from 'prom-client';
import * as uuid from 'uuid';
import uuid from 'uuid';

import { SchemaError } from './error/SchemaError';
import { ServiceModule } from './module/ServiceModule';
Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function loadConfig(name: string, ...extras: Array<string>): Promis
const paths = completePaths(name, extras);

for (const p of paths) {
console.log('reading config from', p);
const data = await readConfig(p);
if (doesExist(data)) {
return safeLoad(data, {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/github/PRController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Octokit from '@octokit/rest';
import Octokit from '@octokit/rest';
import { Inject } from 'noicejs';

import { CheckRBAC, Controller, ControllerData, Handler } from '..';
Expand Down
2 changes: 1 addition & 1 deletion src/controller/kubernetes/AppsController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as k8s from '@kubernetes/client-node';
import k8s from '@kubernetes/client-node';
import { Inject } from 'noicejs';

import { CheckRBAC, Controller, Handler } from '..';
Expand Down
2 changes: 1 addition & 1 deletion src/controller/kubernetes/BaseController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as k8s from '@kubernetes/client-node';
import k8s from '@kubernetes/client-node';
import { Inject } from 'noicejs';

import { Controller, ControllerData } from '..';
Expand Down
2 changes: 1 addition & 1 deletion src/controller/kubernetes/CoreController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as k8s from '@kubernetes/client-node';
import k8s from '@kubernetes/client-node';
import { Inject } from 'noicejs';

import { CheckRBAC, Controller, Handler } from '..';
Expand Down
2 changes: 1 addition & 1 deletion src/listener/GithubListener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Octokit from '@octokit/rest';
import Octokit from '@octokit/rest';
import { Inject } from 'noicejs';
import { Repository } from 'typeorm';

Expand Down
13 changes: 10 additions & 3 deletions src/locale/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import i18next from 'i18next';
import { readFileSync } from 'fs';
import { safeLoad } from 'js-yaml';
import { isNil } from 'lodash';
import { Container, Inject, Logger } from 'noicejs';

import { BaseService, BaseServiceOptions, INJECT_LOGGER } from '../BaseService';
Expand All @@ -7,6 +10,12 @@ import { mustExist } from '../utils';
import { classLogger } from '../utils/logger';
import { LocaleLogger } from '../utils/logger/LocaleLogger';

const LOCALE_STRING = readFileSync('./src/locale/en.yml', 'utf-8');
if (isNil(LOCALE_STRING)) {
throw new Error('unable to load schema from file');
}
const LOCALE_GLOBAL = safeLoad(LOCALE_STRING);

export interface LocaleData {
lang: string;
}
Expand Down Expand Up @@ -42,9 +51,7 @@ export class Locale extends BaseService<LocaleData> implements ServiceLifecycle
debug: true,
lng: this.data.lang,
resources: {
/* tslint:disable:no-var-requires */
en: require('src/locale/en.yml'),
/* tslint:enable:no-var-requires */
en: LOCALE_GLOBAL,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/LexParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as AWS from 'aws-sdk';
import AWS from 'aws-sdk';
import { isNil, isString, kebabCase } from 'lodash';
import { MissingValueError } from 'noicejs';

Expand Down
2 changes: 1 addition & 1 deletion src/schema/graph/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as express from 'express';
import express from 'express';
import { GraphQLList, GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { isNil } from 'lodash';
import { Inject } from 'noicejs';
Expand Down
12 changes: 9 additions & 3 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as Ajv from 'ajv';
import Ajv from 'ajv';
import { readFileSync } from 'fs';
import { safeLoad } from 'js-yaml';
import { isNil } from 'lodash';

import { InvalidArgumentError } from '../error/InvalidArgumentError';
import { SCHEMA_KEYWORD_REGEXP } from './keyword/Regexp';

/* tslint:disable-next-line:no-var-requires */
export const SCHEMA_GLOBAL = require('src/schema/schema.yml');
const SCHEMA_STRING = readFileSync('./src/schema/schema.yml', 'utf-8');
if (isNil(SCHEMA_STRING)) {
throw new Error('unable to load schema from file');
}
const SCHEMA_GLOBAL = safeLoad(SCHEMA_STRING);

export interface SchemaResult {
errors: Array<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/schema/keyword/Regexp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Ajv from 'ajv';
import Ajv from 'ajv';
import { isBoolean } from 'lodash';

export const SCHEMA_KEYWORD_REGEXP: Ajv.KeywordDefinition = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/BunyanLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as bunyan from 'bunyan';
import bunyan from 'bunyan';
import { Logger } from 'noicejs';

import { prototypeName } from '.';
Expand All @@ -12,6 +12,7 @@ export class BunyanLogger {
...options,
serializers: {
...bunyan.stdSerializers,
container: prototypeName,
logger: prototypeName,
module: prototypeName,
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/JsonPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as jp from 'jsonpath';
import jp from 'jsonpath';

import { TemplateScope } from './Template';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/Math.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNil } from 'lodash';
import * as mathjs from 'mathjs';
import mathjs from 'mathjs';

import { TemplateScope } from './Template';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/TemplateCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Handlebars from 'handlebars';
import Handlebars from 'handlebars';
import { BaseOptions, Inject, Logger } from 'noicejs';

import { mustExist } from '.';
Expand Down
23 changes: 9 additions & 14 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
// webpack environment defines
declare const BUILD_JOB: string;
declare const BUILD_RUNNER: string;
declare const GIT_BRANCH: string;
declare const GIT_COMMIT: string;
declare const NODE_VERSION: string;
declare const WEBPACK_VERSION: string;

export const VERSION_INFO = {
app: {
name: '{{ APP_NAME }}',
version: '{{ APP_VERSION }}',
},
build: {
job: BUILD_JOB,
node: NODE_VERSION,
runner: BUILD_RUNNER,
webpack: WEBPACK_VERSION,
job: '{{ BUILD_JOB }}',
node: '{{ NODE_VERSION }}',
runner: '{{ BUILD_RUNNER }}',
},
git: {
branch: GIT_BRANCH,
commit: GIT_COMMIT,
branch: '{{ GIT_BRANCH }}',
commit: '{{ GIT_COMMIT }}',
},
};
14 changes: 4 additions & 10 deletions test/harness.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { ineeda } from 'ineeda';
import * as sinonChai from 'sinon-chai';
import * as sourceMapSupport from 'source-map-support';
import sinonChai from 'sinon-chai';
import sourceMapSupport from 'source-map-support';

import { BotModule } from '../src/module/BotModule';
import { EntityModule } from '../src/module/EntityModule';
Expand Down Expand Up @@ -54,9 +54,3 @@ const modules = [
ServiceModule,
TransformModule,
];

// tslint:disable-next-line:no-any
const testContext = (require as any).context('../test', true, /Test.*$/);
testContext.keys().forEach(testContext);
// tslint:disable-next-line:no-default-export
export default testContext;
5 changes: 4 additions & 1 deletion test/module/TestServiceModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { spy } from 'sinon';

import { ServiceModule } from '../../src/module/ServiceModule';
import { Service, ServiceEvent } from '../../src/Service';
import { defer } from '../../src/utils/Async';
import { describeAsync, itAsync } from '../helpers/async';
import { createContainer } from '../helpers/container';

Expand All @@ -17,7 +18,7 @@ async function createModule() {
const testSvc = ineeda<Service>(metadata);

const module = new ServiceModule({
timeout: 100,
timeout: 10,
});
module.bind(TEST_SERVICE_NAME).toInstance(testSvc);

Expand Down Expand Up @@ -55,6 +56,8 @@ describeAsync('DI modules', async () => {
await module.stop();
expect(start).to.have.callCount(1);
expect(stop).to.have.callCount(1);

await defer(50);
});

itAsync('should create and save child services', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/TestBunyanLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as bunyan from 'bunyan';
import bunyan from 'bunyan';
import { expect } from 'chai';

import { BunyanLogger } from '../../src/utils/BunyanLogger';
Expand Down
3 changes: 3 additions & 0 deletions vendor/schema/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "./schema.yml" {
export = {};
}
Loading

0 comments on commit 3d9ea24

Please sign in to comment.