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:
@@ -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'),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user