Skip to content

Commit

Permalink
fix(duplicated-defaults-keys): Fix Duplicated Default Keys Assigned v…
Browse files Browse the repository at this point in the history
…ia Object.assigbn (#217)

* fix(duplicated-defaults-keys): I was using Winston and discovered this minor error, it's caused by modules using Object.assign to assign keys, which isn't picked up by the current filter

* fix(fs): Old Node needs this import instead

* fix(fs): Oops, missed this function usage during my refactor

* fix: Minor change, move the filtering out via Defaults

* BREAKING CHANGE: This is potentially a major change, I'm uncertain if any modules or current projects actually rely upon this "bug" Please create an issue if anything is broken after this release.
  • Loading branch information
EntraptaJ committed Feb 8, 2021
1 parent 7a179a6 commit 5d819ce
Show file tree
Hide file tree
Showing 18 changed files with 13,103 additions and 289 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Code Quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
node: ['14.x']
node: ['15.x']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -35,7 +35,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
node: ['14.x']
node: ['15.x']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
29 changes: 25 additions & 4 deletions .github/workflows/Push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- master

jobs:
Test:
name: Tests
IntegrationTest:
name: Integration Tests
strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
Expand All @@ -27,5 +27,26 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Run Tests
run: npm run test
- name: Run Integration Tests
run: npm run test:integration

# UnitTests:
# name: Unit Tests
# strategy:
# matrix:
# os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
# node: ['13.9', '13.10', '13.11', '14.1', '14.4', '14.15.1', '>=14.15.0']
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v2

# - uses: actions/setup-node@v2.1.4
# with:
# node-version: ${{ matrix.node }}
# registry-url: 'https://registry.npmjs.org'

# - name: Install dependencies
# run: npm ci

# - name: Run Unit Tests
# run: npm run test:integration
40 changes: 40 additions & 0 deletions Testing/Runner/Utils/findTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Testing/Runner/Utils/findTests.ts
import { promises as fs } from 'fs';
import { resolve } from 'path';
import { resolvePath } from './resolvePath';

interface TestFolder {
testName: string;

testFolderPath: string;
}

export async function findTestFolders(): Promise<TestFolder[]> {
const testsFolderPath = resolvePath('../../Tests/', import.meta.url);

const testFolders = await fs.readdir(testsFolderPath, {
encoding: 'utf-8',
withFileTypes: false,
});

return Promise.all(
testFolders.map(async (testFolderName) => {
const testFolderPath = resolve(testsFolderPath, testFolderName);

try {
const packageJSONFile = await fs.readFile(
resolve(testFolderPath, 'package.json'),
);

const packageJSON = JSON.parse(packageJSONFile.toString());

return {
testName: packageJSON.name,
testFolderPath: testFolderPath,
} as TestFolder;
} catch {
return undefined;
}
}),
);
}
52 changes: 52 additions & 0 deletions Testing/Runner/Utils/moduleFileFinder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Testing/Runner/Utils/moduleFileFinder.ts
import { promises as fs } from 'fs';
import { resolvePath } from './resolvePath';
import { resolve } from 'path';
import { pathToFileURL } from 'url';
type FileMatcher = RegExp;

const coreModulesDir = resolvePath('../Modules', import.meta.url);

/**
* Finds module files that match the fileMatcher
* @param
*/
export async function findModuleFiles<T>(
fileMatcher: FileMatcher,
rootDir: string = coreModulesDir,
): Promise<T[]> {
const timerKey = `findModuleFiles-${rootDir}`;

console.time(timerKey);

async function processDirectory(directoryPath: string): Promise<T[]> {
const directoryContents = await fs.readdir(directoryPath, {
encoding: 'utf-8',
withFileTypes: true,
});

return Promise.all(
directoryContents.flatMap((directoryContent) => {
const contentPath = resolve(directoryPath, directoryContent.name);

if (directoryContent.isDirectory()) {
return processDirectory(contentPath);
}

if (fileMatcher.test(directoryContent.name) === true) {
return import(pathToFileURL(contentPath).href) as Promise<T>;
}

return [];
}),
);
}

const results = await processDirectory(rootDir);

const flatResults = results.flat(50);

console.timeEnd(timerKey);

return flatResults;
}
30 changes: 23 additions & 7 deletions Testing/Runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
// Testing/Runner/index.ts
import { installTestsDependencies } from './Utils/installTestsDependencies';
import { run } from './Utils/run';
import { promises as fs } from 'fs';
import { findTestFolders } from './Utils/findTests';

async function runTests(): Promise<void> {
await installTestsDependencies();
const testFolders = await findTestFolders();

try {
await fs.symlink(process.cwd(), 'node_modules/@k-foss/ts-esnode', 'dir');
} catch {}

try {
await run('npx ts-estest ./Testing/Tests', {
cwd: process.cwd(),
const errs: Error[] = [];

for (const testFolder of testFolders) {
console.log(`Starting Test Folder: ${testFolder.testName}`);

await run('npm ci', {
cwd: testFolder.testFolderPath,
});
} catch {
process.exit(1);

console.log(`Packages installed`);

try {
await run('npx ts-estest ./src', {
cwd: testFolder.testFolderPath,
});
} catch (err) {
errs.push(err);
}
}

if (errs.length > 0) {
throw errs;
}
}

Expand Down
4 changes: 1 addition & 3 deletions Testing/Tests/TSConfig/src/TSConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export class TSConfigTestSuite extends TestSuite {
'renderModule(App)',
);

process.env.TS_CONFIG_PATH = resolve(
'Testing/Tests/TSConfig/tsconfig.random.json',
);
process.env.TS_CONFIG_PATH = resolve('tsconfig.random.json');

const { Main } = await import('./Main');

Expand Down
4 changes: 1 addition & 3 deletions Testing/Tests/TSConfigExtends/src/TSConfigExtends.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export class TSConfigExtendsTestSuite extends TestSuite {
'renderModule(App)',
);

process.env.TS_CONFIG_PATH = resolve(
'Testing/Tests/TSConfigExtends/tsconfig.random.json',
);
process.env.TS_CONFIG_PATH = resolve('tsconfig.random.json');

const { Main } = await import('./Main');

Expand Down
Loading

0 comments on commit 5d819ce

Please sign in to comment.