Skip to content

Commit

Permalink
chore: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rudouglas committed Nov 30, 2021
1 parent 908a2e1 commit bb6c24f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
58 changes: 30 additions & 28 deletions scripts/actions/__tests__/add-files-to-translation-queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ This is a test file
};

const EXCLUSIONS = {
excludePath: { 'ja-JP': ['excluded/path'] },
excludeType: { 'ja-JP': ['excludedType'] },
excludePath: { jp: ['excluded/path'], kr: ['excluded/path'] },
excludeType: { jp: ['excludedType'], kr: ['excludedType'] },
};

const mockReadFileSync = (translate = []) => {
Expand Down Expand Up @@ -123,44 +123,46 @@ describe('add-files-to-translation-queue tests', () => {
expect(toBeTranslated).toEqual([
{
filename: '/content/bar.mdx',
fileType: 'landingPage',
contentType: 'landingPage',
locale: 'ja-JP',
project_id: 'HT_ID',
},
]);
});
test('Doesnt exclude any files', async () => {

test('Doesnt exclude any files from translation', async () => {
const files = [
{ filename: 'included/path/content/bar.mdx', locale: 'ja-JP' },
{ filename: 'included/path/content/foo.mdx', locale: 'ja-JP' },
{ filename: 'included/path/content/bar.mdx', locale: 'jp' },
{ filename: 'included/path/content/foo.mdx', locale: 'jp' },
];
const includedFiles = excludeFiles(files, EXCLUSIONS);

expect(includedFiles).toEqual([
{ filename: 'included/path/content/bar.mdx', locale: 'ja-JP' },
{ filename: 'included/path/content/foo.mdx', locale: 'ja-JP' },
{ filename: 'included/path/content/bar.mdx', locale: 'jp' },
{ filename: 'included/path/content/foo.mdx', locale: 'jp' },
]);
});

test('Excludes files under a set path', async () => {
const files = [
{
filename: 'included/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'kr',
},
{
filename: 'excluded/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'jp',
},
];
const includedFiles = excludeFiles(files, EXCLUSIONS);

expect(includedFiles).toEqual([
{
filename: 'included/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'kr',
},
]);
});
Expand All @@ -169,22 +171,22 @@ describe('add-files-to-translation-queue tests', () => {
const files = [
{
filename: 'included/path/content/bar.mdx',
fileType: 'excludedType',
locale: 'ja-JP',
contentType: 'excludedType',
locale: 'kr',
},
{
filename: 'included/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'jp',
},
];
const includedFiles = excludeFiles(files, EXCLUSIONS);

expect(includedFiles).toEqual([
{
filename: 'included/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'jp',
},
]);
});
Expand All @@ -193,27 +195,27 @@ describe('add-files-to-translation-queue tests', () => {
const files = [
{
filename: 'included/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'kr',
},
{
filename: 'included/path/content/bar.mdx',
fileType: 'excludedType',
locale: 'ja-JP',
contentType: 'excludedType',
locale: 'jp',
},
{
filename: 'excluded/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'jp',
},
];
const includedFiles = excludeFiles(files, EXCLUSIONS);

expect(includedFiles).toEqual([
{
filename: 'included/path/content/bar.mdx',
fileType: 'doc',
locale: 'ja-JP',
contentType: 'doc',
locale: 'kr',
},
]);
});
Expand Down
14 changes: 7 additions & 7 deletions scripts/actions/add-files-to-translation-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const getExclusions = () => {
*/
const excludeFiles = (fileData, exclusions) => {
return fileData.filter(
({ filename, locale, fileType }) =>
!exclusions.excludePath[locale]?.some((exclus) =>
filename.includes(exclus)
) &&
!exclusions.excludeType[locale]?.some((exclus) => fileType === exclus)
({ filename, locale, contentType }) =>
!exclusions.excludePath[locale]?.some((path) =>
filename.startsWith(path)
) && !exclusions.excludeType[locale]?.some((type) => contentType === type)
);
};

/**
* Determines if a particular locale should be human or machine translated based on the files frontmatter.
*
Expand All @@ -72,11 +72,11 @@ const getLocalizedFileData = (prFile) => {
const contents = fs.readFileSync(path.join(process.cwd(), prFile.filename));
const { data } = frontmatter(contents);
const checkLocale = getProjectId(data.translate);
const fileType = data.type;
const contentType = data.type;

return Object.keys(LOCALE_IDS).map((locale) => ({
...prFile,
fileType,
contentType,
locale: LOCALE_IDS[locale],
project_id: checkLocale(locale),
}));
Expand Down

0 comments on commit bb6c24f

Please sign in to comment.