Some Text-Runner actions create files and folders on disk. These files and folders get created in a temporary directory called the workspace so that they don't interfere with the codebase that you document. This package provides Text-Runner actions for interacting with this Text-Runner workspace.
npm i -D textrun-workspace
The workspace/new-directory action creates a directory with the given name in the workspace. Here is a usage example:
Create a directory named <b type="workspace/new-directory">utils</b>.
When executing this Markdown snippet, Text-Runner will create a utils directory in the workspace, just as the user would.
Each Text-Runner test starts in the workspace directory. The workspace/working-dir action changes the current working directory of the test runner to the given directory inside the workspace. To change into the directory the reader created above:
Please change into the
<code type="workspace/working-dir">utils</code>
folder.
The workspace/new-file action creates a file in the workspace. This action assumes that the documentation writes the filename in emphasized or bold text, or inside a "filename" attribute, and the file content is a code block with one or three backticks. Here are a few examples:
<a type="workspace/new-file">
Create file _apples.txt_ with the content `Fuji apples are the best`.
</a>
<a type="workspace/new-file">
Create file **apples.txt** with the content:
```
Fuji apples are the best
```
</a>
When executing the documentation, Text-Runner will create a file with name
apples.txt and content
Fuji apples are the best
in the workspace.
The workspace/empty-file action creates an empty file.
An example is this documentation:
Please create an empty file <b type="workspace/empty-file">.gitkeep</b>.
When executing the documentation, Text-Runner will create a file with name .gitkeep in the workspace.
The workspace/existing-directory action verifies that the workspace contains a directory with the given name. As an example, consider this documentation snippet:
Please run the command <code type="shell/command">mkdir images</code>. If
everything goes well, your computer will now have a new directory
<i type="workspace/existing-directory">images</i>. You can store images in it.
The workspace/existing-file action verifies that a file with the given name exists and has the given content. This action assumes that the documentation contains the filename as emphasized or strong text and the file content as a code block with single or triple backticks. As an example, consider the following documentation snippet:
Assuming a file <a type="workspace/new-file">_hello.txt_ with content
`hello world`</a>, we can verify it via this action:
<a type="workspace/existing-file-with-content">The file _hello.txt_ now contains
`hello world`.</a>
By default, actions in this plugin create the files in the workspace. To create
them in a different directory, provide a dir
attribute at the region marker
containing the relative path to the directory to use. As an example, consider
the following documentation snippet:
<a type="workspace/new-file" dir="subdir">
Please create a file _apples.txt_ with the content `Boskoop`.
</a>
When executing the documentation, Text-Runner will create a file
subdir/apples.txt and content Boskoop
.