mirror of
https://github.com/laurent22/joplin.git
synced 2026-10-25 02:47:28 +00:00
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { readFile } from 'fs/promises';
|
|
import { isAutoGeneratedFile } from './checkGeneratedFiles';
|
|
import { join } from 'path';
|
|
|
|
const readTestFile = () => readFile(join(__dirname, 'checkGeneratedFiles.test.js'), 'utf-8');
|
|
|
|
describe('checkGeneratedFiles', () => {
|
|
it('should detect an older auto-generated .js file processed by eslint', () => {
|
|
const generatedFile = `
|
|
'use strict';
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
exports.default = function() {};
|
|
// # sourceMappingURL=test.js.map
|
|
`.trimStart();
|
|
expect(isAutoGeneratedFile(generatedFile)).toBe(true);
|
|
});
|
|
|
|
it('should detect a newer auto-generated .js file', async () => {
|
|
const fileContent = await readTestFile();
|
|
expect(isAutoGeneratedFile(fileContent)).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
// The correct comment should ignore the check
|
|
['ignore: generated check', true],
|
|
// A different comment should not ignore the check
|
|
['do not ignore: generated check', false],
|
|
])('should allow ignoring the generated check (case %#)', async (commentText, shouldIgnore) => {
|
|
let fileContent = await readTestFile();
|
|
// Add the comment just after the first line:
|
|
fileContent = fileContent.replace('\n', `\n// ${commentText}\n`);
|
|
expect(isAutoGeneratedFile(fileContent)).toBe(!shouldIgnore);
|
|
});
|
|
});
|