Skip to content

Commit

Permalink
fix(contented-pipeline-jest-md): fix raw filename parsing (#590)
Browse files Browse the repository at this point in the history
#### What this PR does / why we need it:

Fix `computeFileName`.
  • Loading branch information
fuxingloh authored Aug 25, 2023
1 parent ee524bc commit 5cddf8f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/contented-example/contented.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const config = {
{
type: 'Contented',
dir: 'packages/contented-example',
pattern: 'jest/**/*.md.unit.[tj]s',
pattern: 'jest/**/*.md.[tj]s',
processor: 'jest-md',
transform: (file) => {
file.sections = file.sections.slice(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/contented-example/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"jest": {
"preset": "@contentedjs/jest-preset",
"testRegex": ".*\\.md\\.unit.[jt]s$"
"testRegex": ".*\\.md\\.[jt]s$"
},
"devDependencies": {
"@contentedjs/jest-preset": "0.0.0"
Expand Down
12 changes: 4 additions & 8 deletions packages/contented-pipeline-jest-md/src/JestMarkdownPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { readFile } from 'node:fs/promises';
import { join, ParsedPath } from 'node:path';
import { join } from 'node:path';

import { parse } from '@babel/parser';
import { File } from '@babel/types';
import { MarkdownPipeline, MarkdownVFile } from '@contentedjs/contented-pipeline-md';
import stripIndent from 'strip-indent';

export class JestMarkdownPipeline extends MarkdownPipeline {
/**
* The file should be named as `file.md.unit.[jt]sx?` the `.md.unit.` middle part to determine
* it's a markdown file that is also a unit test file.
*/
protected override computePath(sections: string[], parsedPath: ParsedPath): string {
const path = super.computePath(sections, parsedPath);
return path.replaceAll(/md-(unit|i9n|e2e|integration|test|tests|spec)$/g, '');
protected computeFileName(rawFileName: string): string {
const rawFile = rawFileName.replaceAll(/\.md$/g, '');
return super.computeFileName(rawFile);
}

protected override async readVFile(rootPath: string, filename: string): Promise<MarkdownVFile | undefined> {
Expand Down

0 comments on commit 5cddf8f

Please sign in to comment.