Skip to content

Commit

Permalink
ci(Check enqueuer version of plugins before loading'em):
Browse files Browse the repository at this point in the history
  • Loading branch information
virgs committed Jun 30, 2019
1 parent df9b095 commit b63ecc0
Show file tree
Hide file tree
Showing 14 changed files with 4,282 additions and 2,562 deletions.
3,562 changes: 2,248 additions & 1,314 deletions output/examples.json

Large diffs are not rendered by default.

3,170 changes: 1,950 additions & 1,220 deletions output/examples.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enqueuer",
"version": "4.3.1",
"version": "5.0.0",
"description": "Polyglot flow testing tool",
"main": "./js/enqueuer.js",
"typings": "./js/enqueuer.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/configurations/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class Configuration {
if (Configuration.loaded === false) {
Configuration.loaded = true;
Configuration.instance = new Configuration();
Logger.setLoggerLevel(Configuration.instance.getLogLevel());
Configuration.instance.commandLineConfiguration.verifyPrematureActions();
if (Configuration.instance.logLevel === 'trace') {
this.printConfiguration();
Expand Down
11 changes: 9 additions & 2 deletions src/enqueuer-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {Configuration} from './configurations/configuration';
import {RequisitionAdopter} from './components/requisition-adopter';
import {NotificationEmitter, Notifications} from './notifications/notification-emitter';
import {SummaryTestOutput} from './outputs/summary-test-output';
import {PublisherModel} from './models/inputs/publisher-model';
import {TestModel} from './models/outputs/test-model';

export class EnqueuerRunner {
private static reportName: string = 'enqueuer';
Expand Down Expand Up @@ -36,10 +38,15 @@ export class EnqueuerRunner {
parallel: configuration.isParallel()
}).getRequisition();
const parsingErrors = requisitionFileParser.getFilesErrors();
const valid = parsingErrors.length === 0;
const finalReports = await new RequisitionRunner(this.enqueuerRequisition).run();
await this.publishReports(configuration.getOutputs(), finalReports, parsingErrors);
return finalReports;
}

private async publishReports(configurationOutputs: PublisherModel[], finalReports: output.RequisitionModel[], parsingErrors: TestModel[]) {
Logger.info('Publishing reports');
const outputs = new MultiTestsOutput(configuration.getOutputs());
const valid = parsingErrors.length === 0;
const outputs = new MultiTestsOutput(configurationOutputs);
await finalReports.map(async report => {
report.hooks!.onParsed = {
valid: valid,
Expand Down
3 changes: 2 additions & 1 deletion src/enqueuer-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export class EnqueuerStarter {
Logger.fatal(`Execution error: ${error}`);
statusCode = -1;
}
Logger.info(`Hope you had a great time`);
Logger.info('Enqueuer execution is over (' + (statusCode === 0) + ')');
Logger.setLoggerLevel('info');
Logger.info(`Hope you had a great time`);
return statusCode;

}
Expand Down
10 changes: 8 additions & 2 deletions src/models-defaults/outputs/requisition-default-reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ export class RequisitionDefaultReports {
},
onFinishTests: TestModel[] = []): output.RequisitionModel {
const valid = onFinishTests.every((test) => test.valid);
return Object.assign({}, base, {
return {
valid: valid,
name: base.name,
id: base.id,
ignored: base.ignored,
level: base.level,
subscriptions: [],
publishers: [],
iterations: base.iterations,
totalIterations: base.totalIterations,
hooks: {
[DefaultHookEvents.ON_INIT]: {
arguments: {},
Expand All @@ -37,7 +43,7 @@ export class RequisitionDefaultReports {
totalTime: 0
},
requisitions: []
});
};
}

public static createRunningError(base: { name: string, id: string }, err: any): output.RequisitionModel {
Expand Down
10 changes: 10 additions & 0 deletions src/outputs/formatters/json-formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ describe('JsonReportFormatter', () => {
expect(format).toBe(new JsonObjectParser().stringify(test));
});

it('Should throw', () => {
const test: RequisitionModel = {
name: 'name',
valid: true,
tests: []
};
test.cycle = test;
expect(() => new JsonReportFormatter().format(test)).toThrow();
});

it('Should export an entry point', done => {
const mainInstance: any = {
reportFormatterManager: {
Expand Down
8 changes: 7 additions & 1 deletion src/outputs/formatters/json-formatter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {ReportFormatter} from './report-formatter';
import {RequisitionModel} from '../../models/outputs/requisition-model';
import {MainInstance} from '../../plugins/main-instance';
import {Logger} from '../../loggers/logger';

export class JsonReportFormatter implements ReportFormatter {
public format(report: RequisitionModel): string {
return JSON.stringify(report, null, 2);
try {
return JSON.stringify(report, null, 2);
} catch (e) {
Logger.warning(e);
throw e;
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/outputs/multi-tests-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ export class MultiTestsOutput {
public async publishReport(report: RequisitionModel) {
await Promise.all(this.outputs
.map(publisher => {
const formatter = publisher.formatter as ReportFormatter;
Logger.trace(`Formatting as ${publisher.format}`);
publisher.payload = formatter.format(report);
return publisher.publish();
try {
const formatter = publisher.formatter as ReportFormatter;
Logger.trace(`Formatting as ${publisher.format}`);
publisher.payload = formatter.format(report);
return publisher.publish();
} catch (err) {
Logger.warning(`Error publishing report: ${JSON.stringify(report)}: ${err}`);
}
}));
}
}
11 changes: 11 additions & 0 deletions src/plugins/dynamic-modules-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,15 @@ describe('DynamicModulesManager', () => {

DynamicModulesManager.getInstance().describeLoadedModules();
});

it('should check enqueuer version of plugins', () => {
// @ts-ignore
expect(DynamicModulesManager.versionMatches({dependencies: {enqueuer: '^5.0.0'}})).toBeTruthy();
// @ts-ignore
expect(DynamicModulesManager.versionMatches({devDependencies: {enqueuer: '5.0.0'}})).toBeTruthy();
// @ts-ignore
expect(DynamicModulesManager.versionMatches({peerDependencies: {enqueuer: '5.0.0'}})).toBeTruthy();
// @ts-ignore
expect(DynamicModulesManager.versionMatches({})).toBeFalsy();
});
});
40 changes: 25 additions & 15 deletions src/plugins/dynamic-modules-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,20 @@ export class DynamicModulesManager {
.map(module => module.replace(/\.js/, ''))
.filter(module => {
try {
const packageJson = JSON.parse(fs.readFileSync(module + '/package.json').toString());
const hasKeyWords = packageJson.keywords
.filter((keyword: string) => keyword.toLowerCase() === 'enqueuer' ||
keyword.toLowerCase() === 'nqr').length > 0;
const versionMatches = DynamicModulesManager.versionMatches(packageJson);
if (hasKeyWords && versionMatches) {
return require(module).entryPoint !== undefined;
const packageJsonPath = module + '/package.json';
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
const keyWordsMatch = (packageJson.keywords || [])
.find((keyword: string) => keyword.toLowerCase() === 'enqueuer' || keyword.toLowerCase() === 'nqr');
if (keyWordsMatch) {
const versionMatches = DynamicModulesManager.versionMatches(packageJson);
if (versionMatches) {
return require(module).entryPoint !== undefined;
}
}
}
} catch (err) {
Logger.trace(err);
}
return false;
});
Expand All @@ -116,15 +121,20 @@ export class DynamicModulesManager {
return [];
}

//TODO test it
private static versionMatches(packageJson: { dependencies: any, devDependencies: any, peerDependencies: any }): boolean {
const regexp = /[ ^d]*(\d+)/;
private static versionMatches(packageJson: { name: string, dependencies: any, devDependencies: any, peerDependencies: any }): boolean {
const regexp = /[^\d]*(\d+)/;
const currentMajorVersion = (process.env.npm_package_version || enqueuerPackageJson.version).match(regexp)[0];
const pluginMajorEnqueuerVersion = (packageJson.dependencies.enqueuer ||
packageJson.devDependencies.enqueuer ||
packageJson.peerDependencies.enqueuer)
.version.match(regexp)[0];
return currentMajorVersion <= pluginMajorEnqueuerVersion;
const enqueuerVersion = (packageJson.dependencies || {}).enqueuer ||
(packageJson.devDependencies || {}).enqueuer ||
(packageJson.peerDependencies || {}).enqueuer ||
'0.0.0';
const pluginMajorEnqueuerVersion = enqueuerVersion.match(regexp)[1];

Logger.trace(`name: ${packageJson.name} => currentMajorVersion (${
+currentMajorVersion}) <= pluginMajorEnqueuerVersion (${
+pluginMajorEnqueuerVersion}): ${
+currentMajorVersion <= +pluginMajorEnqueuerVersion}`);
return +currentMajorVersion <= +pluginMajorEnqueuerVersion;
}

private loadModule(module: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/requisition-runners/requisition-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class RequisitionRunner {
}
}

private async executeChild(child: input.RequisitionModel, index: number) {
private async executeChild(child: input.RequisitionModel, index: number): Promise<output.RequisitionModel[]> {
child.parent = this.requisition;
const childRunner = new RequisitionRunner(child);
this.childrenRequisitionRunner.push(childRunner);
Expand Down

0 comments on commit b63ecc0

Please sign in to comment.