Skip to content

Commit 7be6d4f

Browse files
committed
removed temporarily test coverage infra
1 parent 0f61f18 commit 7be6d4f

10 files changed

+116
-1557
lines changed

package-lock.json

+84-1,480
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
"description": "OData EDM generator",
55
"type": "module",
66
"exports": {
7-
"require": "./dist/cjs/api/decorators.js",
8-
"import": "./dist/esm/decorators.js"
7+
"import": "./dist/esm/api/decorators.js"
98
},
10-
"typings": "dist/types/decorators",
9+
"typings": "dist/types/api/decorators",
1110
"bin": {
12-
"gen-edm": "dist/cjs/cli/index.js"
11+
"gen-edm": "dist/esm/cli/index.js"
1312
},
1413
"scripts": {
1514
"lint": "eslint . --ext .ts --cache",
1615
"prebuild": "rimraf dist && npm run lint",
17-
"build": "tsc && tsc -p tsconfig.esm.json",
16+
"build": "tsc",
1817
"dev": "tsc -w --preserveWatchOutput",
1918
"pretest": "tsc -p tests/tsconfig.json",
20-
"test": "mocha ./tests/.artifacts/dist/tests/**/*.js",
21-
"test_original": "nyc --nycrc-path ./tests/nyc.config.js mocha --config ./tests/.mocharc.js",
22-
"test:dev": "cross-env DEV=true nyc --nycrc-path ./tests/nyc.config.cjs mocha --config ./tests/.mocharc.cjs --bail"
19+
"test": "mocha --config ./tests/.mocharc.cjs",
20+
"test:dev": "mocha --config ./tests/.mocharc.cjs --bail"
2321
},
2422
"repository": {
2523
"type": "git",
@@ -61,9 +59,7 @@
6159
"husky": "^9.0.11",
6260
"mocha": "^10.2.0",
6361
"mock-fs": "^5.2.0",
64-
"nyc": "^15.1.0",
6562
"rimraf": "^5.0.1",
66-
"source-map-support": "^0.5.21",
6763
"standard-version": "^9.5.0",
6864
"ts-node": "^10.9.1",
6965
"typescript": "^5.4.2",

src/cli/configuration.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { promises as fs } from 'fs';
33
import { isAbsolute, resolve } from 'path';
44
import { EndpointConfiguration, Logger } from './shared.js';
55
import { exists as exists } from './file-system-helper.js';
6+
import { pathToFileURL } from 'url';
67

78
export class Configuration {
89

@@ -37,8 +38,9 @@ export class Configuration {
3738
if (!await exists(configPath) || !(await fs.stat(configPath)).isFile()) {
3839
throw new Error(`The config file "${configPath}" does not exist.`);
3940
}
40-
// eslint-disable-next-line @typescript-eslint/no-var-requires
41-
await instance.applyConfiguration(await require(configPath) as ConfigSchema);
41+
let importedConfig = await import(pathToFileURL(configPath).href) as ConfigSchema & { default?: ConfigSchema };
42+
importedConfig = importedConfig.default as ConfigSchema ?? importedConfig;
43+
await instance.applyConfiguration(importedConfig);
4244
break;
4345
}
4446
case 'endpoint':

tests/.mocharc.cjs

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
const path = require("path");
2-
const { register } = require('node:module');
3-
const { pathToFileURL } = require('node:url');
4-
5-
const cwd = pathToFileURL("./");
6-
register(
7-
"ts-node/esm",
8-
cwd,
9-
{ project: path.resolve(cwd.href, './tests/tsconfig.json') }
10-
);
11-
12-
const isDev = !!process.env.DEV;
131
module.exports = {
14-
// extension: ['ts', 'js'],
15-
spec: './tests/**/*.spec.ts',
16-
// "node-option": [
17-
// "loader=ts-node/esm"
18-
// ],
19-
// require: [path.resolve('./tests/ts-hook.cjs')/* , 'source-map-support/register' */],
20-
// reporter: '@netatwork/mocha-utils/dist/JunitSpecReporter.js',
21-
// reporterOptions: ['mochaFile=./tests/.artifacts/results.xml'],
22-
// ...(isDev ? { watch: true, 'watch-files': './**/*.ts' } : {})
2+
spec: './tests/.artifacts/dist/tests/**/*.spec.js',
3+
reporter: '@netatwork/mocha-utils/dist/JunitSpecReporter.js',
4+
reporterOptions: ['mochaFile=./tests/.artifacts/results.xml'],
235
};

tests/generator.spec.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
import { assert } from 'chai';
77
import { gray, green, red } from 'colorette';
88
import { diffLines } from 'diff';
9-
import { Dirent, promises as fs } from 'fs';
9+
import { promises as fs, readdirSync } from 'fs';
1010
import mockFs from 'mock-fs';
1111
import type { DirectoryItems } from 'mock-fs/lib/filesystem';
12-
import { join } from 'path';
1312
import { URL } from 'node:url';
13+
import { join } from 'path';
1414
import { v4 as uuid } from 'uuid';
1515
import { Configuration } from '../src/cli/configuration.js';
16+
import { exists } from '../src/cli/file-system-helper.js';
1617
import { $Generator } from '../src/cli/generator.js';
1718
import { Endpoint, EndpointConfiguration } from '../src/cli/shared.js';
18-
import { exists } from '../src/cli/file-system-helper.js';
1919

2020
const __dirname = process.cwd();
2121

@@ -65,14 +65,10 @@ describe('generator', function () {
6565
}
6666

6767
const dataPath = join(__dirname, 'tests', 'data');
68-
let directoryEntries: Dirent[] = [];
69-
before(async function () {
70-
directoryEntries = (await fs.readdir(dataPath, { encoding: 'utf8', withFileTypes: true }))
71-
.filter((x) => x.isDirectory());
72-
});
73-
for (const dirent of directoryEntries) {
68+
for (const dirent of (readdirSync(dataPath, { encoding: 'utf8', withFileTypes: true }))
69+
.filter((x) => x.isDirectory())) {
7470
const dirName = dirent.name;
75-
it.only(`works for ${dirName}`, async function () {
71+
it(`works for ${dirName}`, async function () {
7672
let generator: $Generator | null = null;
7773
try {
7874
// arrange
@@ -81,15 +77,17 @@ describe('generator', function () {
8177
const inputDir = join(caseDir, 'input');
8278

8379
const mockFsConfig: DirectoryItems = { [baseOutputPath]: {} };
84-
const configFilePath = join(inputDir, 'config.js');
80+
const configFilePath = join(inputDir, 'config.cjs');
8581

8682
let configuredEndpoints: EndpointConfiguration[] | undefined = undefined;
8783
let hasConfiguredEndpoints = false;
8884
const args = ['--outputDir', baseOutputPath];
89-
if (await exists(configFilePath)) {
85+
if (await mockFs.bypass(() => exists(configFilePath))) {
9086
args.unshift('--config', configFilePath);
9187
mockFsConfig[configFilePath] = mockFs.load(configFilePath);
92-
configuredEndpoints = (await import(`file:///${configFilePath}`)).endpoints;
88+
let importedConfig = await import(`file:///${configFilePath}`);
89+
importedConfig = importedConfig.default ?? importedConfig;
90+
configuredEndpoints = importedConfig.endpoints;
9391
hasConfiguredEndpoints = Array.isArray(configuredEndpoints) && configuredEndpoints.length > 0;
9492
}
9593
if (!hasConfiguredEndpoints) {
@@ -102,12 +100,11 @@ describe('generator', function () {
102100

103101
for (const ep of configuration.endpoints) {
104102
let epInput = join(inputDir, new URL(ep.url).hostname);
105-
epInput = await exists(epInput) ? epInput : inputDir;
103+
epInput = await mockFs.bypass(() => exists(epInput)) ? epInput : inputDir;
106104

107-
const edmxXml = await fs.readFile(join(epInput, 'metadata.xml'), 'utf8');
108-
console.log('[test] edmxXml', edmxXml);
105+
const edmxXml = await mockFs.bypass(() => fs.readFile(join(epInput, 'metadata.xml'), 'utf8'));
109106
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
110-
const endpoints: Endpoint[] = JSON.parse(await fs.readFile(join(epInput, 'endpoints.json'), 'utf8')).value;
107+
const endpoints: Endpoint[] = JSON.parse(await mockFs.bypass(() => fs.readFile(join(epInput, 'endpoints.json'), 'utf8'))).value;
111108

112109
// act
113110
await generator.generateEndpointsFile(endpoints, ep);

tests/nyc.config.cjs

-7
This file was deleted.

tests/ts-hook.cjs

-1
This file was deleted.

tests/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"target": "ES6",
55
"module": "ES2020",
66
"outDir": "./.artifacts/dist",
7-
"declaration": false,
87
},
98
"include": [
109
"../tests"

tsconfig.esm.json

-14
This file was deleted.

tsconfig.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"compilerOptions": {
33
"target": "ESNext",
4-
"module": "ES6",
4+
"module": "ES2020",
55
"lib": [
6-
"ESNext",
76
"dom"
87
],
9-
"declaration": false,
8+
"declaration": true,
9+
"declarationMap": true,
10+
"declarationDir": "./dist/types",
1011
"sourceMap": true,
11-
"outDir": "./dist/cjs",
12+
"outDir": "./dist/esm",
1213
"strict": true,
1314
"moduleResolution": "node",
1415
"esModuleInterop": true,

0 commit comments

Comments
 (0)