Skip to content

Commit

Permalink
#45: allow test skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jul 22, 2024
1 parent 8804505 commit 69988f1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Added ability to skip a test by using the `skip` keyword as the test command [#45](https://github.com/lando/leia/issues/45)
* Added a `--timeout` option
* Changed default `timeout` to 30 minutes
* Improved usage in `--help`
Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,29 @@ npx leia
Cleverly converts markdown files into mocha cli tests

USAGE
$ leia <files> <patterns> [options]
$ leia <files> <patterns> [--cleanup-header=<cleanup-headers>] [--debug] [--help] [--ignore=<patterns>] [--retry=<count>] [--setup-header=<setup-headers>] [--test-header=<test-headers>]
[--shell=<bash|cmd|powershell|pwsh|sh|zsh>] [--stdin] [--timeout=<seconds>] [--version]

ARGUMENTS
TESTS files or patterns to scan for test

OPTIONS
-c, --cleanup-header=cleanup-header [default: Clean,Tear,Burn] sections that start with these headers are cleanup commands
-h, --help show CLI help
-i, --ignore=ignore files or patterns to ignore
-r, --retry=retry [default: 1] the amount of retries a failing test should get
-s, --setup-header=setup-header [default: Start,Setup,This is the dawning] sections that start with these headers are setup commands
-t, --test-header=test-header [default: Test,Validat,Verif] sections that start with these headers are tests
-v, --version show CLI version
--debug show debug output
--shell=shell the shell to use for the tests, default is autodetected
--stdin attach stdin when the test is run
-c, --cleanup-header=cleanup-header [default: Clean,Tear,Burn] considers these h2 sections as cleanup commands
-i, --ignore=ignore files or patterns to ignore
-r, --retry=retry [default: 1] retries tests the given amount
-s, --setup-header=setup-header [default: Start,Setup,This is the dawning] considers these h2 sections as setup commands
-t, --test-header=test-header [default: Test,Validat,Verif] considers these h2 sections as tests
-v, --version shows version info
--debug shows debug output
--help shows help
--shell=bash|cmd|powershell|pwsh|sh|zsh [default: /opt/homebrew/bin/zsh] runs tests with given shell, autodetected by default
--stdin attachs stdin when the test is run
--timeout=timeout [default: 1800] seconds before tests time out

EXAMPLES
leia README.md
leia README.md "examples/**/*.md" --retry 6 --test-header Tizzestin
leia "examples/*.md" --ignore BUTNOTYOU.md test --stdin
leia "examples/*.md" --ignore BUTNOTYOU.md test --stdin --timeout 5
leia README.md --shell cmd
```

Expand Down Expand Up @@ -125,6 +127,15 @@ cat test.txt

If you want to learn more about the syntax and how `leia` puts together the above, check out [this example](https://github.com/lando/leia/blob/main/examples/basic-example.md)

## Skipping

You can also skip tests. This is useful if you want to stub out a test to do later but don't have the time to do right now.

```bash
# Should write this test later and dont want to forget it
skip
```

## Environment Variables

`leia` will also set the following environment variables for each test that is running so you can use them for stuff.
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ env | grep TEST3
unset TEST
unset TEST2
unset TEST3

# Should be a test we have right now but we dont so this is just a stub to remind us
skip
```

You can also add aditional code blocks under a section. This allows you to better organize and structure your markdown file.
Expand Down
1 change: 1 addition & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const parseCodeBlock = ({text, file, shell}) => {
args: scriptArgs.replace('{0}', scriptPath),
shell: shell.binary.split(path.sep).join('/'),
command: parseTestCommand(test, shell.name),
skip: parseTestCommand(test, shell.name) === 'skip',
script: scriptPath,
describe: _.map(_.filter(test.split(newLine), (line) => _.startsWith(line, '#')), parseTestDescribe),
};
Expand Down
4 changes: 2 additions & 2 deletions templates/test.def
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
process.env.LEIA_TEST_NUMBER = '{{=test.number}}';
process.env.LEIA_TEST_RETRY = this.ctx.test._currentRetry;
process.env.LEIA_TEST_STAGE = '{{=test.section}}';

{{? test.skip }}this.ctx.test.skip();{{?? true }}
const cli = new CliTest();
const data = {shell: '{{=test.shell}}', args: `{{=test.args}}`, commands: `{{=test.command}}`, stdin: '{{=it.stdin}}'};
debug(`running test {{=it.id}} from {{=it.cwd}} using %o`, data);
Expand All @@ -15,5 +15,5 @@
const error = [`CODE: ${res.error.code}`, `STDOUT: ${res.stdout}`, `STDERR: ${res.stderr}`].join('\n');
done(new Error(error));
}
});
});{{?}}
});

0 comments on commit 69988f1

Please sign in to comment.