Refactor to remove code coupling with Webpack

Remove using Webpack import syntax such as: `js-yaml-loader!@/..`. It's
a non-standard syntax that couples the code to Webpack.

Configure instead by specifying Webpack loader in Vue configuration
file.

Enable related ESLint rules.

Remove unused dependency `raw-loader` and refactor
`NoUnintendedInlining` test to load files using file system (dropping
webpack dependency).

Refactor to use `import type` for type imports to show the indent
clearly and satisfy failing ESLint rules.
This commit is contained in:
undergroundwires
2022-01-30 08:25:23 +01:00
parent db47440d47
commit 5bbbb9cecc
32 changed files with 273 additions and 195 deletions

View File

@@ -1,10 +1,10 @@
import 'mocha';
import { expect } from 'chai';
import { CollectionData } from 'js-yaml-loader!@/*';
import type { CollectionData } from '@/application/collections/';
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
import { CategoryCollectionParserType, parseApplication } from '@/application/Parser/ApplicationParser';
import WindowsData from 'js-yaml-loader!@/application/collections/windows.yaml';
import MacOsData from 'js-yaml-loader!@/application/collections/macos.yaml';
import WindowsData from '@/application/collections/windows.yaml';
import MacOsData from '@/application/collections/macos.yaml';
import { IProjectInformation } from '@/domain/IProjectInformation';
import { ProjectInformation } from '@/domain/ProjectInformation';
import { ICategoryCollection } from '@/domain/ICategoryCollection';

View File

@@ -1,6 +1,6 @@
import 'mocha';
import { expect } from 'chai';
import { DocumentableData } from 'js-yaml-loader!@/*';
import type { DocumentableData } from '@/application/collections/';
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';

View File

@@ -1,6 +1,6 @@
import 'mocha';
import { expect } from 'chai';
import { FunctionCallParametersData } from 'js-yaml-loader!@/*';
import type { FunctionCallParametersData } from '@/application/collections/';
import { FunctionCallCompiler } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/FunctionCallCompiler';
import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
import { IExpressionsCompiler } from '@/application/Parser/Script/Compiler/Expressions/IExpressionsCompiler';

View File

@@ -1,6 +1,6 @@
import 'mocha';
import { expect } from 'chai';
import { FunctionData } from 'js-yaml-loader!@/*';
import type { FunctionData } from '@/application/collections/';
import { ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
import { SharedFunctionsParser } from '@/application/Parser/Script/Compiler/Function/SharedFunctionsParser';
import { FunctionDataStub } from '@tests/unit/shared/Stubs/FunctionDataStub';

View File

@@ -1,6 +1,6 @@
import 'mocha';
import { expect } from 'chai';
import { FunctionData } from 'js-yaml-loader!@/*';
import type { FunctionData } from '@/application/collections/';
import { ILanguageSyntax, ScriptCode } from '@/domain/ScriptCode';
import { ScriptCompiler } from '@/application/Parser/Script/Compiler/ScriptCompiler';
import { ISharedFunctionsParser } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionsParser';

View File

@@ -1,7 +1,7 @@
import 'mocha';
import { resolve, join, basename } from 'path';
import { readdirSync, readFileSync } from 'fs';
import { expect } from 'chai';
import WindowsData from 'raw-loader!@/application/collections/windows.yaml';
import MacOsData from 'raw-loader!@/application/collections/macos.yaml';
/*
A common mistake when working with yaml files to forget mentioning that a value should
@@ -17,19 +17,13 @@ import MacOsData from 'raw-loader!@/application/collections/macos.yaml';
These tests can be considered as "linter" more than "unit-test" and therefore can lead
to false-positives.
*/
describe('collection files to have no unintended inlining', async () => {
describe('collection files to have no unintended inlining', () => {
// arrange
const testCases = [{
name: 'macos',
fileContent: MacOsData,
}, {
name: 'windows',
fileContent: WindowsData,
},
];
const testCases = createTestCases('src/application/collections/');
for (const testCase of testCases) {
it(`${testCase.name}`, async () => {
const lines = await findBadLineNumbers(testCase.fileContent);
// act
const lines = await findBadLineNumbers(testCase.content);
// assert
expect(lines).to.be.have.lengthOf(0, printMessage());
function printMessage(): string {
@@ -57,6 +51,9 @@ function findLineNumbersEndingWith(content: string, ending: string): number[] {
}
function sanityCheck(content: string, ending: string): void {
if (!content) {
throw new Error('File content is empty, is the file loaded correctly?');
}
if (!content.includes(ending)) {
throw new Error(
`File does not contain string "${ending}" string at all.`
@@ -64,3 +61,22 @@ function sanityCheck(content: string, ending: string): void {
);
}
}
interface ITestCase {
name: string;
content: string;
}
function createTestCases(collectionsDirFromRoot: string): ITestCase[] {
const collectionsDir = resolve(`./${collectionsDirFromRoot}`);
const fileNames = readdirSync(collectionsDir);
if (fileNames.length === 0) {
throw new Error(`Could not find any collection in ${collectionsDir}`);
}
const collectionFilePaths = fileNames
.filter((name) => name.endsWith('.yaml'))
.map((name) => join(collectionsDir, name));
return collectionFilePaths.map((path) => ({
name: basename(path),
content: readFileSync(path, 'utf-8'),
}));
}