Skip to content

Commit

Permalink
Make interpreter work with absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed Jul 30, 2024
1 parent 2401fe0 commit b9b9629
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 52 deletions.
11 changes: 0 additions & 11 deletions apps/interpreter/src/current-dir.ts

This file was deleted.

23 changes: 4 additions & 19 deletions apps/interpreter/src/examples-smoke-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,6 @@ vi.mock('sqlite3', () => {
};
});

// simulate as if we were starting the jv cli in the example dir
vi.mock('./current-dir', () => {
const currentDirMock = () =>
path.join(
path.dirname(fileURLToPath(import.meta.url)), // relative to this test file
'..',
'..',
'..',
'example',
);
return {
getCurrentDir: currentDirMock,
};
});

describe('jv example smoke tests', () => {
const defaultOptions: RunOptions = {
pipeline: '.*',
Expand Down Expand Up @@ -105,7 +90,7 @@ describe('jv example smoke tests', () => {
});
sqliteLoaderMock.setup();

await runAction('cars.jv', {
await runAction('example/cars.jv', {
...defaultOptions,
});

Expand Down Expand Up @@ -137,7 +122,7 @@ describe('jv example smoke tests', () => {
postgresLoaderMock.setup();
sqliteLoaderMock.setup();

await runAction('electric-vehicles.jv', {
await runAction('example/electric-vehicles.jv', {
...defaultOptions,
env: new Map<string, string>([
['DB_HOST', 'mock'],
Expand Down Expand Up @@ -200,7 +185,7 @@ describe('jv example smoke tests', () => {
});
sqliteLoaderMock.setup();

await runAction('gtfs-rt.jv', {
await runAction('example/gtfs-rt.jv', {
...defaultOptions,
});

Expand Down Expand Up @@ -228,7 +213,7 @@ describe('jv example smoke tests', () => {
});
sqliteLoaderMock.setup();

await runAction('gtfs-static.jv', {
await runAction('example/gtfs-static.jv', {
...defaultOptions,
});

Expand Down
24 changes: 7 additions & 17 deletions apps/interpreter/src/parse-only.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,11 @@ const interpreterMock: JayveeInterpreter = {
vi.stubGlobal('DefaultJayveeInterpreter', interpreterMock);

const dirPathOfThisTest = path.dirname(fileURLToPath(import.meta.url));
const pathExamplesRelativeToThisTest = path.join('..', '..', '..', 'example');

// simulate as if we were starting the jv cli in the example dir
vi.mock('./current-dir', () => {
const currentDirMock = () =>
path.join(dirPathOfThisTest, pathExamplesRelativeToThisTest);
return {
getCurrentDir: currentDirMock,
};
});
const pathProjectRootRelativeToThisTest = path.join('..', '..', '..');

describe('Parse Only', () => {
const pathToValidModelFromExamplesDir = 'cars.jv';
const pathToInvalidModelFromExamplesDir = path.join(
'..',
const pathToValidModelFromProjectRoot = path.join('example', 'cars.jv');
const pathToInvalidModelFromProjectRoot = path.join(
'apps',
'interpreter',
'test',
Expand Down Expand Up @@ -68,7 +58,7 @@ describe('Parse Only', () => {

it('should exit with 0 on a valid option', async () => {
await expect(
runAction(pathToValidModelFromExamplesDir, {
runAction(pathToValidModelFromProjectRoot, {
...defaultOptions,
parseOnly: true,
}),
Expand All @@ -81,13 +71,13 @@ describe('Parse Only', () => {
it('should exit with 1 on error', async () => {
const modelPathRelativeToThisTest = path.join(
dirPathOfThisTest,
pathExamplesRelativeToThisTest,
pathToInvalidModelFromExamplesDir,
pathProjectRootRelativeToThisTest,
pathToInvalidModelFromProjectRoot,
);
expect(fs.existsSync(modelPathRelativeToThisTest)).toBe(true);

await expect(
runAction(pathToInvalidModelFromExamplesDir, {
runAction(pathToInvalidModelFromProjectRoot, {
...defaultOptions,
parseOnly: true,
}),
Expand Down
11 changes: 6 additions & 5 deletions apps/interpreter/src/run-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
type JayveeServices,
} from '@jvalue/jayvee-language-server';

import { getCurrentDir } from './current-dir';
import { parsePipelineMatcherRegExp, parseRunOptions } from './run-options';

export async function runAction(
Expand All @@ -35,9 +34,9 @@ export async function runAction(
return process.exit(ExitCode.FAILURE);
}

const currentDir = getCurrentDir();
const currentDir = process.cwd();
const workingDir = currentDir;
const absoluteFilePath = path.join(currentDir, filePath);
const filePathRelativeToCurrentDir = path.relative(currentDir, filePath);

const interpreter = new DefaultJayveeInterpreter({
pipelineMatcher: (pipelineDefinition) =>
Expand All @@ -49,10 +48,12 @@ export async function runAction(
}).addWorkspace(workingDir);

if (options.parseOnly === true) {
return await runParseOnly(absoluteFilePath, interpreter);
return await runParseOnly(filePathRelativeToCurrentDir, interpreter);
}

const exitCode = await interpreter.interpretFile(absoluteFilePath);
const exitCode = await interpreter.interpretFile(
filePathRelativeToCurrentDir,
);
process.exit(exitCode);
}

Expand Down

0 comments on commit b9b9629

Please sign in to comment.