Skip to content

feat: Regex and environmental variable support added#7

Merged
kidunot89 merged 1 commit intomasterfrom
feat/env-and-regex-support
Jul 2, 2024
Merged

feat: Regex and environmental variable support added#7
kidunot89 merged 1 commit intomasterfrom
feat/env-and-regex-support

Conversation

@kidunot89
Copy link

@kidunot89 kidunot89 commented Jul 2, 2024

Summary

  • Replaces runFrom parameter with options parameter on the execute and spawn callbacks.

    const options: Partial<{
      runFrom: string, // where to execute command from.
      env: Record<string, unknown>, // environment variables to be set on the process when the command is executed
      timeout: number, // execute only
    }> | undefined = {};
    const { execute, spawn, cleanup } = await prepareEnvironment();
    
    const executeResult = await execute(
        'node',
        './test/testing-cli-entry.js env',
        { env: { HELLO: 'WORLD' } }
    );
    expect(executeResult).exitCodeToBe(0);
    expect(executeResult.stdout).toContain('- HELLO: WORLD');
    
    const { waitForText, waitForFinish } = await spawn(
        'node',
        './test/testing-cli-entry.js env',
        { env: { HELLO: 'UNIVERSE', NODE_ENV: 'Yes' } }
    );
    
    expect(await waitForText('- HELLO: UNIVERSE')).toBeFoundInOutput();
    expect(await waitForText('- NODE_ENV: Yes')).toBeFoundInOutput();
    expect(await waitForFinish()).exitCodeToBe(0);
    
    await cleanup();
  • useRegex added to the options parameter for waitForText for more sophisticated captures.
    Note: Expression must be passed as a string with escaped backslashes e.g. "\\d+ dogs, \\d+ cats, and \\d+ birds"

    const { spawn, cleanup } = await prepareEnvironment();
    
    const {
        waitForText,
        waitForFinish,
    } = await spawn('node', './test/testing-cli-entry.js random');
    
    expect(
        await waitForText('\\d+ dogs, \\d+ cats, and \\d+ birds', { useRegex: true })
    ).toBeFoundInOutput();
  • README.md updated.

@kidunot89 kidunot89 merged commit 0b79967 into master Jul 2, 2024
@kidunot89 kidunot89 deleted the feat/env-and-regex-support branch July 2, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant