diff --git a/package.json b/package.json index 5ab79ae..57c1747 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -49,8 +54,6 @@ "typescript": "^5.4.5" }, "dependencies": { - "lodash": "^4.17.21", - "make-dir": "^3.1.0", "xmlbuilder": "^15.1.1" }, "release-it": { diff --git a/src/builder.ts b/src/builder.ts index 1462ed2..1868f83 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -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; @@ -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'); } diff --git a/src/factory.ts b/src/factory.ts index c384e6a..8d68021 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -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 { /** diff --git a/src/index.ts b/src/index.ts index 3da7ab1..fbe7175 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/test_case.ts b/src/test_case.ts index a66d721..50f892f 100755 --- a/src/test_case.ts +++ b/src/test_case.ts @@ -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 { diff --git a/src/test_group.ts b/src/test_group.ts index 8d681ed..834b1f1 100755 --- a/src/test_group.ts +++ b/src/test_group.ts @@ -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)[]; @@ -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; @@ -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; diff --git a/src/test_node.ts b/src/test_node.ts index ce18ff7..3aada74 100644 --- a/src/test_node.ts +++ b/src/test_node.ts @@ -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 @@ -66,7 +65,7 @@ export abstract class TestNode { /** * @param parentElement - the parent element */ - build(parentElement?: XMLElement) { + build(parentElement?: xmlBuilder.XMLElement) { return this.buildNode(this.createElement(parentElement)); } @@ -74,7 +73,7 @@ export abstract class TestNode { * @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); } @@ -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]); @@ -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, diff --git a/src/test_suite.ts b/src/test_suite.ts index 71587c6..e87695f 100755 --- a/src/test_suite.ts +++ b/src/test_suite.ts @@ -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 { /** diff --git a/src/test_suites.ts b/src/test_suites.ts index a2cf9d3..f53af12 100755 --- a/src/test_suites.ts +++ b/src/test_suites.ts @@ -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 { /** diff --git a/tsconfig.json b/tsconfig.json index 0e36c6d..3bb7c88 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,8 @@ { "compilerOptions": { - "target": "es2018", - "module": "commonjs", - "moduleResolution": "node", - "lib": ["es2015"], + "target": "es2020", + "module": "Node16", + "lib": ["es2020"], "rootDir": "src", "outDir": "lib", @@ -28,9 +27,9 @@ "declaration": true, "pretty": true, - "esModuleInterop": true, + "esModuleInterop": false, "types": ["node", "jest"] }, - "include": ["typings/**/*", "src/**/*"] + "include": ["src/**/*"] }