Skip to content

Commit

Permalink
chore: extract custom config
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Jan 20, 2025
1 parent 194576f commit cfb5d68
Showing 1 changed file with 66 additions and 28 deletions.
94 changes: 66 additions & 28 deletions test/e2e/extractCustom.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fileURLToPathSlash } from './utils/toFilePath.js';
import { run } from './utils/run.js';
import { createTmpFolderWithConfig, removeTmpFolder } from './utils/tmp.js';

const FIXTURES_PATH = new URL('../__fixtures__/', import.meta.url);
const FAKE_PROJECT = new URL('./customExtractors/', FIXTURES_PATH);
Expand All @@ -11,31 +12,68 @@ const TS_EXTRACTOR = fileURLToPathSlash(
new URL('./extract-ts.ts', FAKE_PROJECT)
);

it('successfully uses a custom extractor written in JS', async () => {
const out = await run(
['extract', 'print', '--extractor', JS_EXTRACTOR, '--patterns', TEST_FILE],
undefined,
50e3
);

console.log(out.stdout);
expect(out.code).toBe(0);
expect(out.stdout).toContain('STR_CRUDE');
expect(out.stdout).toContain('STR_WORKING');
expect(out.stdout).toContain('STR_NEW');
expect(out.stdout).toContain('STR_PRODUCTION');
}, 60e3);

it('successfully uses a custom extractor written in TS', async () => {
const out = await run(
['extract', 'print', '--extractor', TS_EXTRACTOR, '--patterns', TEST_FILE],
undefined,
50e3
);

expect(out.code).toBe(0);
expect(out.stdout).toContain('STR_CRUDE');
expect(out.stdout).toContain('STR_WORKING');
expect(out.stdout).toContain('STR_NEW');
expect(out.stdout).toContain('STR_PRODUCTION');
}, 60e3);
describe('custom extractor', () => {
it('successfully uses a custom extractor written in JS (arg)', async () => {
afterEach(async () => {
await removeTmpFolder();
});

const out = await run(
[
'extract',
'print',
'--extractor',
JS_EXTRACTOR,
'--patterns',
TEST_FILE,
],
undefined,
50e3
);

expect(out.code).toBe(0);
expect(out.stdout).toContain('STR_CRUDE');
expect(out.stdout).toContain('STR_WORKING');
expect(out.stdout).toContain('STR_NEW');
expect(out.stdout).toContain('STR_PRODUCTION');
}, 60e3);

it('successfully uses a custom extractor written in JS (config)', async () => {
const { configFile } = await createTmpFolderWithConfig({
extractor: JS_EXTRACTOR,
patterns: [TEST_FILE],
});
const out = await run(
['-c', configFile, 'extract', 'print'],
undefined,
50e3
);

expect(out.code).toBe(0);
expect(out.stdout).toContain('STR_CRUDE');
expect(out.stdout).toContain('STR_WORKING');
expect(out.stdout).toContain('STR_NEW');
expect(out.stdout).toContain('STR_PRODUCTION');
}, 60e3);

it('successfully uses a custom extractor written in TS', async () => {
const out = await run(
[
'extract',
'print',
'--extractor',
TS_EXTRACTOR,
'--patterns',
TEST_FILE,
],
undefined,
50e3
);

expect(out.code).toBe(0);
expect(out.stdout).toContain('STR_CRUDE');
expect(out.stdout).toContain('STR_WORKING');
expect(out.stdout).toContain('STR_NEW');
expect(out.stdout).toContain('STR_PRODUCTION');
}, 60e3);
});

0 comments on commit cfb5d68

Please sign in to comment.