textrun-workspace 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -44
- package/dist/actions/empty-file.js +18 -0
- package/dist/actions/existing-file-with-content.js +35 -0
- package/dist/actions/existing-file.js +4 -13
- package/dist/actions/new-file.js +3 -2
- package/dist/actions/working-dir.js +1 -1
- package/dist/index.js +6 -2
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
# Text-Runner Actions for the Text-Runner workspace
|
|
1
|
+
# Text-Runner Actions for the Text-Runner test workspace
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
3
|
+
Some Text-Runner actions create files and folders on disk. These files and
|
|
4
|
+
folders get created in a temporary directory called the _workspace_ so that they
|
|
5
|
+
don't interfere with the codebase that you document. This package provides
|
|
6
|
+
[Text-Runner](https://github.com/kevgo/text-runner) actions for interacting with
|
|
7
|
+
this Text-Runner workspace.
|
|
8
8
|
|
|
9
9
|
### installation
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<pre type="npm/install">
|
|
14
|
-
$ npm i -D textrun-workspace
|
|
15
|
-
</pre>
|
|
16
|
-
|
|
17
|
-
or
|
|
18
|
-
|
|
19
|
-
<pre type="npm/install">
|
|
20
|
-
$ yarn i -D textrun-workspace
|
|
21
|
-
</pre>
|
|
22
|
-
|
|
23
|
-
### cd action
|
|
11
|
+
<a type="npm/install">
|
|
24
12
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
example, consider the following documentation snippet:
|
|
28
|
-
|
|
29
|
-
<a type="extension/runnable-region">
|
|
30
|
-
|
|
31
|
-
```html
|
|
32
|
-
Create a
|
|
33
|
-
<code type="workspace/new-directory">foo</code>
|
|
34
|
-
directory. Now you can change into it via this Markdown code:
|
|
35
|
-
<code type="workspace/working-dir">foo</code>
|
|
13
|
+
```
|
|
14
|
+
npm i -D textrun-workspace
|
|
36
15
|
```
|
|
37
16
|
|
|
38
17
|
</a>
|
|
@@ -54,35 +33,51 @@ When executing this Markdown snippet, Text-Runner will create a
|
|
|
54
33
|
<i type="workspace/existing-directory">utils</i> directory in the workspace,
|
|
55
34
|
just as the user would.
|
|
56
35
|
|
|
36
|
+
### working-dir
|
|
37
|
+
|
|
38
|
+
Each Text-Runner test starts in the workspace directory. The
|
|
39
|
+
<b type="action/name-full">workspace/working-dir</b> action changes the current
|
|
40
|
+
working directory of the test runner to the given directory inside the
|
|
41
|
+
workspace. To change into the directory the reader created above:
|
|
42
|
+
|
|
43
|
+
<a type="extension/runnable-region">
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
Please change into the
|
|
47
|
+
<code type="workspace/working-dir">utils</code>
|
|
48
|
+
folder.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
</a>
|
|
52
|
+
|
|
57
53
|
### create-file
|
|
58
54
|
|
|
59
55
|
The <b type="action/name-full">workspace/new-file</b> action creates a file in
|
|
60
56
|
the workspace. This action assumes that the documentation writes the filename in
|
|
61
|
-
_emphasized_ or **bold** text
|
|
62
|
-
three backticks.
|
|
57
|
+
_emphasized_ or **bold** text, or inside a "filename" attribute, and the file
|
|
58
|
+
content is a code block with one or three backticks. Here are a few examples:
|
|
63
59
|
|
|
64
60
|
<a type="extension/runnable-region">
|
|
65
61
|
|
|
66
62
|
```markdown
|
|
67
|
-
<a type="workspace/new-file">
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
<a type="workspace/new-file">
|
|
64
|
+
|
|
65
|
+
Create file _apples.txt_ with the content `Fuji apples are the best`.
|
|
70
66
|
|
|
71
67
|
</a>
|
|
68
|
+
```
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
<a type="workspace/existing-file">_apples.txt_ and content `Fuji`</a>.
|
|
75
|
-
Alternatively, the documentation could also read like this:
|
|
70
|
+
</a>
|
|
76
71
|
|
|
77
72
|
<a type="extension/runnable-region">
|
|
78
73
|
|
|
79
74
|
````markdown
|
|
80
75
|
<a type="workspace/new-file">
|
|
81
76
|
|
|
82
|
-
|
|
77
|
+
Create file **apples.txt** with the content:
|
|
83
78
|
|
|
84
79
|
```
|
|
85
|
-
|
|
80
|
+
Fuji apples are the best
|
|
86
81
|
```
|
|
87
82
|
|
|
88
83
|
</a>
|
|
@@ -90,8 +85,27 @@ Gala
|
|
|
90
85
|
|
|
91
86
|
</a>
|
|
92
87
|
|
|
93
|
-
|
|
94
|
-
<a type="workspace/existing-file">
|
|
88
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
89
|
+
<a type="workspace/existing-file-with-content">_apples.txt_ and content
|
|
90
|
+
`Fuji apples are the best`</a> in the workspace.
|
|
91
|
+
|
|
92
|
+
### empty-file
|
|
93
|
+
|
|
94
|
+
The <b type="action/name-full">workspace/empty-file</b> action creates an empty
|
|
95
|
+
file.
|
|
96
|
+
|
|
97
|
+
An example is this documentation:
|
|
98
|
+
|
|
99
|
+
<a type="extension/runnable-region">
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
Please create an empty file <b type="workspace/empty-file">.gitkeep</b>.
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
</a>
|
|
106
|
+
|
|
107
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
108
|
+
<i type="workspace/existing-file">.gitkeep</i> in the workspace.
|
|
95
109
|
|
|
96
110
|
### directory
|
|
97
111
|
|
|
@@ -123,7 +137,7 @@ example, consider the following documentation snippet:
|
|
|
123
137
|
Assuming a file <a type="workspace/new-file">_hello.txt_ with content
|
|
124
138
|
`hello world`</a>, we can verify it via this action:
|
|
125
139
|
|
|
126
|
-
<a type="workspace/existing-file">The file _hello.txt_ now contains
|
|
140
|
+
<a type="workspace/existing-file-with-content">The file _hello.txt_ now contains
|
|
127
141
|
`hello world`.</a>
|
|
128
142
|
```
|
|
129
143
|
|
|
@@ -146,7 +160,7 @@ Please create a file _apples.txt_ with the content `Boskoop`.
|
|
|
146
160
|
|
|
147
161
|
</a>
|
|
148
162
|
|
|
149
|
-
<a type="workspace/existing-file">
|
|
163
|
+
<a type="workspace/existing-file-with-content">
|
|
150
164
|
|
|
151
165
|
When executing the documentation, Text-Runner will create a file
|
|
152
166
|
_subdir/apples.txt_ and content `Boskoop`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as color from "colorette";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as textRunner from "text-runner-engine";
|
|
5
|
+
export async function emptyFile(action) {
|
|
6
|
+
var _a;
|
|
7
|
+
const fileName = action.region.text().trim();
|
|
8
|
+
if (fileName === "") {
|
|
9
|
+
throw new textRunner.UserError("No filename given", "");
|
|
10
|
+
}
|
|
11
|
+
const filePath = path.join((_a = action.region[0].attributes["dir"]) !== null && _a !== void 0 ? _a : ".", fileName);
|
|
12
|
+
action.name(`create file ${color.cyan(filePath)}`);
|
|
13
|
+
const fullPath = action.configuration.workspace.joinStr(filePath);
|
|
14
|
+
action.log(`create file ${filePath}`);
|
|
15
|
+
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
16
|
+
await fs.writeFile(fullPath, "");
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=empty-file.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as assertNoDiff from "assert-no-diff";
|
|
2
|
+
import * as color from "colorette";
|
|
3
|
+
import { promises as fs } from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import * as textRunner from "text-runner-engine";
|
|
6
|
+
export async function existingFileWithContent(action) {
|
|
7
|
+
const fileName = action.region.textInNodeOfType("strong", "em");
|
|
8
|
+
const fileRelPath = path.join(action.region[0].attributes["dir"] || ".", fileName);
|
|
9
|
+
action.name(`verify content of file ${color.cyan(fileRelPath)}`);
|
|
10
|
+
const fullPath = action.configuration.workspace.joinStr(fileRelPath);
|
|
11
|
+
const expectedContent = action.region.textInNodeOfType("fence", "code");
|
|
12
|
+
action.log(expectedContent);
|
|
13
|
+
try {
|
|
14
|
+
var actualContent = await fs.readFile(fullPath, "utf-8");
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
if (!textRunner.isFsError(e)) {
|
|
18
|
+
throw e;
|
|
19
|
+
}
|
|
20
|
+
if (e.code === "ENOENT") {
|
|
21
|
+
const files = await fs.readdir(action.configuration.sourceDir.platformified());
|
|
22
|
+
throw new textRunner.UserError(`file not found: ${fileRelPath}`, `the workspace has these files: ${files.join(", ")}`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
assertNoDiff.trimmedLines(actualContent.trim(), expectedContent.trim());
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw new textRunner.UserError(`mismatching content in ${color.cyan(color.bold(fileRelPath))}`, textRunner.errorMessage(err));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=existing-file-with-content.js.map
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import * as assertNoDiff from "assert-no-diff";
|
|
2
1
|
import * as color from "colorette";
|
|
3
2
|
import { promises as fs } from "fs";
|
|
4
3
|
import * as path from "path";
|
|
5
|
-
import * as textRunner from "text-runner-
|
|
4
|
+
import * as textRunner from "text-runner-engine";
|
|
6
5
|
export async function existingFile(action) {
|
|
7
|
-
const fileName = action.region.
|
|
6
|
+
const fileName = action.region.text();
|
|
8
7
|
const fileRelPath = path.join(action.region[0].attributes["dir"] || ".", fileName);
|
|
9
|
-
action.name(`verify
|
|
8
|
+
action.name(`verify existence of file ${color.cyan(fileRelPath)}`);
|
|
10
9
|
const fullPath = action.configuration.workspace.joinStr(fileRelPath);
|
|
11
|
-
const expectedContent = action.region.textInNodeOfType("fence", "code");
|
|
12
|
-
action.log(expectedContent);
|
|
13
10
|
try {
|
|
14
|
-
|
|
11
|
+
await fs.stat(fullPath);
|
|
15
12
|
}
|
|
16
13
|
catch (e) {
|
|
17
14
|
if (!textRunner.isFsError(e)) {
|
|
@@ -25,11 +22,5 @@ export async function existingFile(action) {
|
|
|
25
22
|
throw e;
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
try {
|
|
29
|
-
assertNoDiff.trimmedLines(actualContent.trim(), expectedContent.trim());
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
throw new textRunner.UserError(`mismatching content in ${color.cyan(color.bold(fileRelPath))}`, textRunner.errorMessage(err));
|
|
33
|
-
}
|
|
34
25
|
}
|
|
35
26
|
//# sourceMappingURL=existing-file.js.map
|
package/dist/actions/new-file.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as color from "colorette";
|
|
2
2
|
import { promises as fs } from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
|
-
import * as textRunner from "text-runner-
|
|
4
|
+
import * as textRunner from "text-runner-engine";
|
|
5
5
|
export async function newFile(action) {
|
|
6
6
|
var _a;
|
|
7
|
+
let fileName = action.region[0].attributes["filename"] || "";
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
+
fileName || (fileName = action.region.textInNodeOfType("em", "strong"));
|
|
9
10
|
}
|
|
10
11
|
catch (e) {
|
|
11
12
|
if (!textRunner.isUserError(e)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as color from "colorette";
|
|
2
|
-
import * as textRunner from "text-runner-
|
|
2
|
+
import * as textRunner from "text-runner-engine";
|
|
3
3
|
/** The "cd" action changes the current working directory to the one given in the hyperlink or code block. */
|
|
4
4
|
export function workingDir(action) {
|
|
5
5
|
const directory = action.region.text();
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { additionalFileContent } from "./actions/additional-file-content.js";
|
|
2
|
+
import { emptyFile } from "./actions/empty-file.js";
|
|
2
3
|
import { existingDirectory } from "./actions/existing-directory.js";
|
|
4
|
+
import { existingFileWithContent } from "./actions/existing-file-with-content.js";
|
|
3
5
|
import { existingFile } from "./actions/existing-file.js";
|
|
4
6
|
import { newDirectory } from "./actions/new-directory.js";
|
|
5
7
|
import { newFile } from "./actions/new-file.js";
|
|
6
8
|
import { workingDir } from "./actions/working-dir.js";
|
|
7
9
|
export const textrunActions = {
|
|
8
10
|
additionalFileContent,
|
|
9
|
-
|
|
10
|
-
newFile,
|
|
11
|
+
emptyFile,
|
|
11
12
|
existingDirectory,
|
|
12
13
|
existingFile,
|
|
14
|
+
existingFileWithContent,
|
|
13
15
|
newDirectory,
|
|
16
|
+
newFile,
|
|
17
|
+
workingDir
|
|
14
18
|
};
|
|
15
19
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textrun-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Text-Runner actions for the Text-Runner workspace",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc -p tsconfig-build.json",
|
|
13
|
-
"clean": "rm -rf dist",
|
|
14
13
|
"cuke": "cucumber-js --format=progress",
|
|
15
|
-
"doc": "text-
|
|
16
|
-
"fix": "eslint --fix --ignore-pattern=dist/ . &&
|
|
17
|
-
"lint": "
|
|
14
|
+
"doc": "text-runner",
|
|
15
|
+
"fix": "eslint --fix --ignore-pattern=dist/ . && dprint fmt && sort-package-json --quiet",
|
|
16
|
+
"lint": "dprint check && sort-package-json --check --quiet && eslint --ignore-pattern=dist/ . && depcheck",
|
|
17
|
+
"reset": "rm -rf dist && yarn run build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"assert-no-diff": "
|
|
20
|
+
"assert-no-diff": "4.1.0",
|
|
21
21
|
"colorette": "2.0.20",
|
|
22
|
-
"text-runner-
|
|
22
|
+
"text-runner-engine": "7.1.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"shared-cucumber-steps": "*",
|
|
26
|
-
"text-runner": "
|
|
27
|
-
"textrun-action": "0.
|
|
28
|
-
"textrun-extension": "0.
|
|
26
|
+
"text-runner": "7.1.2",
|
|
27
|
+
"textrun-action": "0.3.1",
|
|
28
|
+
"textrun-extension": "0.3.1",
|
|
29
29
|
"tsx": "4.19.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "8aa3f5d9fbf24776eae6516b96ebde4863ad33a2"
|
|
32
32
|
}
|