Skip to content

Commit

Permalink
Revert D66760119: Extract logic to get Fantom test config to a standa…
Browse files Browse the repository at this point in the history
…lone module

Differential Revision:
D66760119

Original commit changeset: e955e8f59669

Original Phabricator Diff: D66760119

fbshipit-source-id: ef77a5cdc87efd81bbe503a2a943b1deef4a7e15
  • Loading branch information
Nikita Rubilov authored and facebook-github-bot committed Dec 5, 2024
1 parent efd57d6 commit eee5d2e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 65 deletions.
64 changes: 0 additions & 64 deletions jest/integration/runner/getFantomTestConfig.js

This file was deleted.

2 changes: 1 addition & 1 deletion jest/integration/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import type {TestSuiteResult} from '../runtime/setup';

import entrypointTemplate from './entrypoint-template';
import getFantomTestConfig from './getFantomTestConfig';
import {
getBuckModeForPlatform,
getDebugInfoFromCommandResult,
getFantomTestConfig,
getShortHash,
runBuck2,
symbolicateStackTrace,
Expand Down
50 changes: 50 additions & 0 deletions jest/integration/runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,60 @@
import {spawnSync} from 'child_process';
import crypto from 'crypto';
import fs from 'fs';
// $FlowExpectedError[untyped-import]
import {extract, parse} from 'jest-docblock';
import os from 'os';
// $FlowExpectedError[untyped-import]
import {SourceMapConsumer} from 'source-map';

type DocblockPragmas = {[key: string]: string | string[]};
type FantomTestMode = 'dev' | 'opt';
type FantomTestConfig = {
mode: FantomTestMode,
};

const DEFAULT_MODE: FantomTestMode = 'dev';

/**
* Extracts the Fantom configuration from the test file, specified as part of
* the docblock comment. E.g.:
*
* ```
* /**
* * @flow strict-local
* * @fantom mode:opt
* *
* ```
*
* So far the only supported option is `mode`, which can be 'dev' or 'opt'.
*/
export function getFantomTestConfig(testPath: string): FantomTestConfig {
const docblock = extract(fs.readFileSync(testPath, 'utf8'));
const pragmas = parse(docblock) as DocblockPragmas;

const config = {
mode: DEFAULT_MODE,
};

const maybeMode = pragmas.fantom_mode;

if (maybeMode != null) {
if (Array.isArray(maybeMode)) {
throw new Error('Expected a single value for @fantom_mode');
}

const mode = maybeMode;

if (mode === 'dev' || mode === 'opt') {
config.mode = mode;
} else {
throw new Error(`Invalid Fantom mode: ${mode}`);
}
}

return config;
}

export function getBuckModeForPlatform(enableRelease: boolean = false): string {
const mode = enableRelease ? 'opt' : 'dev';

Expand Down

0 comments on commit eee5d2e

Please sign in to comment.