Skip to content

Commit

Permalink
fix: change tsconfig and package exports for types to match output
Browse files Browse the repository at this point in the history
Also removed unneeded dependencies that we can just use node inbuilts as we only support node >= 16
  • Loading branch information
SimeonC committed Jul 30, 2024
1 parent caad0c7 commit f0cdcfe
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 44 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"name": "junit-report-builder",
"version": "4.0.0",
"description": "Aimed at making it easier to build Jenkins compatible JUnit XML reports in plugins for testing frameworks",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js"
}
},
"main": "./lib/index.js",
"scripts": {
"prepublish": "npm run build",
Expand Down Expand Up @@ -36,7 +42,6 @@
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.0",
"@types/node": "^20.12.7",
"@types/rimraf": "^4.0.5",
"jest": "^29.7.0",
Expand All @@ -49,8 +54,6 @@
"typescript": "^5.4.5"
},
"dependencies": {
"lodash": "^4.17.21",
"make-dir": "^3.1.0",
"xmlbuilder": "^15.1.1"
},
"release-it": {
Expand Down
15 changes: 7 additions & 8 deletions src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from 'path';
import makeDir from 'make-dir';
import fs from 'fs';
import { TestSuites } from './test_suites';
import { TestCase } from './test_case';
import { TestSuite } from './test_suite';
import { Factory } from './factory';
import * as path from 'path';
import * as fs from 'fs';
import { TestSuites } from './test_suites.js';
import { TestCase } from './test_case.js';
import { TestSuite } from './test_suite.js';
import { Factory } from './factory.js';

export class JUnitReportBuilder {
private _rootTestSuites: TestSuites;
Expand All @@ -19,7 +18,7 @@ export class JUnitReportBuilder {
* @param reportPath
*/
writeTo(reportPath: string) {
makeDir.sync(path.dirname(reportPath));
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
fs.writeFileSync(reportPath, this.build(), 'utf8');
}

Expand Down
8 changes: 4 additions & 4 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JUnitReportBuilder } from './builder';
import { TestSuites } from './test_suites';
import { TestSuite } from './test_suite';
import { TestCase } from './test_case';
import { JUnitReportBuilder } from './builder.js';
import { TestSuites } from './test_suites.js';
import { TestSuite } from './test_suite.js';
import { TestCase } from './test_case.js';

export class Factory {
/**
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Factory } from './factory';
import { Factory } from './factory.js';

export default new Factory().newBuilder();
export type { JUnitReportBuilder as Builder } from './builder';
export type { JUnitReportBuilder as Builder } from './builder.js';
export type { TestSuites } from './test_suites.js';
export type { TestCase } from './test_case.js';
export type { TestSuite } from './test_suite.js';
3 changes: 1 addition & 2 deletions src/test_case.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash';
import { TestNode } from './test_node';
import { TestNode } from './test_node.js';
import type { XMLElement } from 'xmlbuilder';

export class TestCase extends TestNode {
Expand Down
13 changes: 6 additions & 7 deletions src/test_group.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _ from 'lodash';
import { TestNode } from './test_node';
import type { TestCase } from './test_case';
import { TestNode } from './test_node.js';
import type { XMLElement } from 'xmlbuilder';
import type { Factory } from './factory';
import type { TestSuite } from './test_suite';
import type { TestCase } from './test_case.js';
import type { Factory } from './factory.js';
import type { TestSuite } from './test_suite.js';

export class TestGroup extends TestNode {
protected _children: (TestCase | TestSuite)[];
Expand All @@ -25,7 +24,7 @@ export class TestGroup extends TestNode {
* @returns this
*/
timestamp(timestamp: string | Date): this {
if (_.isDate(timestamp)) {
if (timestamp instanceof Date) {
this._attributes.timestamp = this.formatDate(timestamp);
} else {
this._attributes.timestamp = timestamp;
Expand Down Expand Up @@ -105,7 +104,7 @@ export class TestGroup extends TestNode {
*/
protected buildNode(element: XMLElement) {
element = super.buildNode(element);
_.forEach(this._children, (child) => {
this._children.forEach((child) => {
child.build(element);
});
return element;
Expand Down
15 changes: 7 additions & 8 deletions src/test_node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import _ from 'lodash';
import xmlBuilder, { type XMLElement } from 'xmlbuilder';
import * as xmlBuilder from 'xmlbuilder';

export abstract class TestNode {
private _elementName: string;
protected _attributes: any;
private _properties: any[];
private _properties: { name: string; value: string }[];

/**
* @param elementName - the name of the XML element
Expand Down Expand Up @@ -66,15 +65,15 @@ export abstract class TestNode {
/**
* @param parentElement - the parent element
*/
build(parentElement?: XMLElement) {
build(parentElement?: xmlBuilder.XMLElement) {
return this.buildNode(this.createElement(parentElement));
}

/**
* @param parentElement - the parent element
* @returns the created element
*/
protected createElement(parentElement?: XMLElement): XMLElement {
protected createElement(parentElement?: xmlBuilder.XMLElement): xmlBuilder.XMLElement {
if (parentElement) {
return parentElement.ele(this._elementName, this._attributes);
}
Expand All @@ -84,7 +83,7 @@ export abstract class TestNode {
/**
* @returns the created root element
*/
private createRootElement(): XMLElement {
private createRootElement(): xmlBuilder.XMLElement {
const element = xmlBuilder.create(this._elementName, { encoding: 'UTF-8', invalidCharReplacement: '' });
Object.keys(this._attributes).forEach((key) => {
element.att(key, this._attributes[key]);
Expand Down Expand Up @@ -119,10 +118,10 @@ export abstract class TestNode {
* @param element
* @returns the created element
*/
protected buildNode(element: XMLElement): XMLElement {
protected buildNode(element: xmlBuilder.XMLElement): xmlBuilder.XMLElement {
if (this._properties.length) {
var propertiesElement = element.ele('properties');
_.forEach(this._properties, (property: any) => {
this._properties.forEach((property) => {
propertiesElement.ele('property', {
name: property.name,
value: property.value,
Expand Down
4 changes: 2 additions & 2 deletions src/test_suite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestGroup } from './test_group';
import type { Factory } from './factory';
import { TestGroup } from './test_group.js';
import type { Factory } from './factory.js';

export class TestSuite extends TestGroup {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/test_suites.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestGroup } from './test_group';
import type { Factory } from './factory';
import { TestGroup } from './test_group.js';
import type { Factory } from './factory.js';

export class TestSuites extends TestGroup {
/**
Expand Down
11 changes: 5 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es2015"],
"target": "es2020",
"module": "Node16",
"lib": ["es2020"],

"rootDir": "src",
"outDir": "lib",
Expand All @@ -28,9 +27,9 @@
"declaration": true,

"pretty": true,
"esModuleInterop": true,
"esModuleInterop": false,

"types": ["node", "jest"]
},
"include": ["typings/**/*", "src/**/*"]
"include": ["src/**/*"]
}

0 comments on commit f0cdcfe

Please sign in to comment.