test: add test for readOutputHTMLFile (#6506)

This commit is contained in:
Joshua Chen 2022-01-29 18:10:46 +08:00 committed by GitHub
parent 8bdecf107c
commit 58e07a6796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 215 deletions

View file

@ -26,6 +26,7 @@ import {
generate,
reportMessage,
posixPath,
readOutputHTMLFile,
} from '../index';
import {sum} from 'lodash';
import fs from 'fs-extra';
@ -362,6 +363,71 @@ describe('findAsyncSequential', () => {
});
});
describe('readOutputHTMLFile', () => {
test('trailing slash undefined', async () => {
await expect(
readOutputHTMLFile(
'/file',
path.join(__dirname, '__fixtures__/build-snap'),
undefined,
).then(String),
).resolves.toEqual('file\n');
await expect(
readOutputHTMLFile(
'/folder',
path.join(__dirname, '__fixtures__/build-snap'),
undefined,
).then(String),
).resolves.toEqual('folder\n');
await expect(
readOutputHTMLFile(
'/file/',
path.join(__dirname, '__fixtures__/build-snap'),
undefined,
).then(String),
).resolves.toEqual('file\n');
await expect(
readOutputHTMLFile(
'/folder/',
path.join(__dirname, '__fixtures__/build-snap'),
undefined,
).then(String),
).resolves.toEqual('folder\n');
});
test('trailing slash true', async () => {
await expect(
readOutputHTMLFile(
'/folder',
path.join(__dirname, '__fixtures__/build-snap'),
true,
).then(String),
).resolves.toEqual('folder\n');
await expect(
readOutputHTMLFile(
'/folder/',
path.join(__dirname, '__fixtures__/build-snap'),
true,
).then(String),
).resolves.toEqual('folder\n');
});
test('trailing slash false', async () => {
await expect(
readOutputHTMLFile(
'/file',
path.join(__dirname, '__fixtures__/build-snap'),
false,
).then(String),
).resolves.toEqual('file\n');
await expect(
readOutputHTMLFile(
'/file/',
path.join(__dirname, '__fixtures__/build-snap'),
false,
).then(String),
).resolves.toEqual('file\n');
});
});
describe('updateTranslationFileMessages', () => {
test('should update messages', () => {
expect(