文件
mynode/packages/tools/checkGeneratedFiles.test.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

35 行
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);
});
});