8000 outline test runner config changes · spencer333/coderoad-vscode@5d55c5a · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d55c5a

Browse files
committed
outline test runner config changes
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent 07aa070 commit 5d55c5a

File tree

7 files changed

+52
-17
lines changed
  • typings
  • 7 files changed

    +52
    -17
    lines changed

    CHANGELOG.md

    Lines changed: 25 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -125,3 +125,28 @@ CODEROAD_TUTORIAL_URL='path/to/tutorial_config_file.json' // will load directly
    125125
    ## [0.6.1]
    126126

    127127
    - Replace checkboxes with icons
    128+
    129+
    ## [0.7.0]
    130+
    131+
    - Change for the test runner config. Changes are backwards compatible.
    132+
    133+
    1. `testRunner.path`=> `testRunner.directory`
    134+
    2. `testRunner.actions` => `testRunner.setup`
    135+
    3. Change command to capture `args` for "TAP" support, and test "filter"ing support. These changes will help lead to specific test suite presets in the future.
    136+
    137+
    ```json
    138+
    {
    139+
    "testRunner": {
    140+
    "command": "mocha",
    141+
    "args": {
    142+
    "filter": "--grep",
    143+
    "tap": "--reporter=mocha-tap-reporter"
    144+
    },
    145+
    "directory": ".coderoad",
    146+
    "setup": {
    147+
    "commits": ["410bd4f"],
    148+
    "commands": ["npm install"]
    149+
    }
    150+
    }
    151+
    }
    152+
    ```

    src/actions/setupActions.ts

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,10 +10,10 @@ import logger from '../services/logger'
    1010
    interface SetupActions {
    1111
    actions: TT.StepActions
    1212
    send: (action: T.Action) => void // send messages to client
    13-
    path?: string
    13+
    dir?: string
    1414
    }
    1515

    16-
    export const setupActions = async ({ actions, send, path }: SetupActions): Promise<void> => {
    16+
    export const setupActions = async ({ actions, send, dir }: SetupActions): Promise<void> => {
    1717
    if (!actions) {
    1818
    return
    1919
    }
    @@ -45,7 +45,7 @@ export const setupActions = async ({ actions, send, path }: SetupActions): Promi
    4545

    4646
    // 4. run command
    4747
    if (!alreadyLoaded) {
    48-
    await runCommands({ commands: commands || [], send, path }).catch(onError)
    48+
    await runCommands({ commands: commands || [], send, dir }).catch(onError)
    4949
    }
    5050
    }
    5151

    src/actions/utils/runCommands.ts

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,10 +4,10 @@ import { exec } from '../../services/node'
    44
    interface RunCommands {
    55
    commands: string[]
    66
    send: (action: T.Action) => void
    7-
    path?: string
    7+
    dir?: string
    88
    }
    99

    10-
    const runCommands = async ({ commands, send, path }: RunCommands) => {
    10+
    const runCommands = async ({ commands, send, dir }: RunCommands) => {
    1111
    if (!commands.length) {
    1212
    return
    1313
    }
    @@ -19,7 +19,7 @@ const runCommands = async ({ commands, send, path }: RunCommands) => {
    1919
    send({ type: 'COMMAND_START', payload: { process: { ...process, status: 'RUNNING' } } })
    2020
    let result: { stdout: string; stderr: string }
    2121
    try {
    22-
    result = await exec({ command, path })
    22+
    result = await exec({ command, dir })
    2323
    console.log(result)
    2424
    } catch (error) {
    2525
    console.log(`Test failed: ${error.message}`)

    src/editor/commands.ts

    Lines changed: 4 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -50,11 +50,12 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
    5050
    // setup 1x1 horizontal layout
    5151
    webview.createOrShow()
    5252
    },
    53-
    [COMMANDS.CONFIG_TEST_RUNNER]: async (config: TT.TutorialTestRunnerConfig) => {
    54-
    if (config.actions) {
    53+
    [COMMANDS.CONFIG_TEST_RUNNER]: async (config: TT.TestRunnerConfig) => {
    54+
    const setup = config.setup || config.actions // TODO: depreacte and remove config.actions
    55+
    if (setup) {
    5556
    // setup tutorial test runner commits
    5657
    // assumes git already exists
    57-
    await setupActions({ actions: config.actions, send: webview.send, path: config.path })
    58+
    await setupActions({ actions: setup, send: webview.send, dir: config.directory || config.path }) // TODO: deprecate and remove config.path
    5859
    }
    5960
    testRunner = createTestRunner(config, {
    6061
    onSuccess: (position: T.Position) => {

    src/services/node/index.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,11 +8,11 @@ const asyncExec = promisify(cpExec)
    88

    99
    interface ExecParams {
    1010
    command: string
    11-
    path?: string
    11+
    dir?: string
    1212
    }
    1313

    1414
    export const exec = (params: ExecParams): Promise<{ stdout: string; stderr: string }> | never => {
    15-
    const cwd = join(WORKSPACE_ROOT, params.path || '')
    15+
    const cwd = join(WORKSPACE_ROOT, params.dir || '')
    1616
    return asyncExec(params.command, { cwd })
    1717
    }
    1818

    src/services/testRunner/index.ts

    Lines changed: 3 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,7 @@ interface Callbacks {
    1818
    const failChannelName = 'CodeRoad (Tests)'
    1919
    const logChannelName = 'CodeRoad (Logs)'
    2020

    21-
    const createTestRunner = (config: TT.TutorialTestRunnerConfig, callbacks: Callbacks) => {
    21+
    const createTestRunner = (config: TT.TestRunnerConfig, callbacks: Callbacks) => {
    2222
    return async (position: T.Position, onSuccess?: () => void): Promise<void> => {
    2323
    logger('createTestRunner', position)
    2424
    const startTime = throttle()
    @@ -34,7 +34,8 @@ const createTestRunner = (config: TT.TutorialTestRunnerConfig, callbacks: Callba
    3434

    3535
    let result: { stdout: string | undefined; stderr: string | undefined }
    3636
    try {
    37-
    result = await exec({ command: config.command, path: config.path })
    37+
    const command = config.args ? `${config.command} ${config?.args.tap}` : config.command // TODO: enforce TAP
    38+
    result = await exec({ command, dir: config.directory || config.path }) // TODO: remove config.path later
    3839
    } catch (err) {
    3940
    result = { stdout: err.stdout, stderr: err.stack }
    4041
    }

    typings/tutorial.d.ts

    Lines changed: 12 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2,7 +2,7 @@ export type Maybe<T> = T | null
    22

    33
    export type TutorialConfig = {
    44
    appVersions: TutorialAppVersions
    5-
    testRunner: TutorialTestRunnerConfig
    5+
    testRunner: TestRunnerConfig
    66
    repo: TutorialRepo
    77
    dependencies?: TutorialDependency[]
    88
    }
    @@ -52,10 +52,18 @@ export type StepActions = {
    5252
    subtasks?: string[]
    5353
    }
    5454

    55-
    export interface TutorialTestRunnerConfig {
    55+
    export interface TestRunnerArgs {
    56+
    filter?: string
    57+
    tap: string
    58+
    }
    59+
    60+
    export interface TestRunnerConfig {
    5661
    command: string
    57-
    path?: string
    58-
    actions?: StepActions
    62+
    args?: TestRunnerArgs
    63+
    path?: string // deprecated
    64+
    directory?: string
    65+
    actions?: StepActions // deprecated
    66+
    setup?: StepActions
    5967
    }
    6068

    6169
    export interface TutorialRepo {

    0 commit comments

    Comments
     (0)
    0