@@ -112,31 +112,29 @@ Let us start from the bottom. The suites will have test files
112
112
with the following general structure:
113
113
114
114
``` ts
115
- import { mod , type ModuleRunner } from ' https://deno.land/x/testjs/mod.ts' ;
115
+ import { describe , type SuiteRunner } from ' https://deno.land/x/testjs/mod.ts' ;
116
116
import { testSubject } from ' ./test-subject.ts' ;
117
117
118
118
// Runs the suites in this file
119
- export const runModule: ModuleRunner = (describe ) => {
120
- describe (' testSubject' , (it ) => {
121
- it (' should do something' , (expect ) => {
122
- // toDoSomething may be any assertion such as toBe
123
- expect (testSubject (), toDoSomething ());
124
- });
119
+ export const runSuite: SuiteRunner = it => {
120
+ it (' should do something' , expect => {
121
+ // toDoSomething may be any assertion such as toBe
122
+ expect (testSubject (), toDoSomething ());
125
123
});
126
124
};
127
125
128
126
export const run = () => {
129
- mod ( ' moduleName ' , runModule );
127
+ describe ( ' suiteName ' , runSuite );
130
128
};
131
129
```
132
130
133
131
For example, the test file for ` email.test.ts ` imports its test subjects
134
132
from ` email.ts ` . The ` testSubject ` may be a function that checks if an email
135
133
has the correct format. The ` toDoSomething ` function may be the ` toMatch ` assertion.
136
134
137
- Notice how ` runModule ` depends on ` mod ` . So, the module that imports ` runModule `
138
- will have to pass ` runModule ` as the second parameter to ` mod `
139
- like ` run ` did: ` mod('moduleName ', runModule )` .
135
+ Notice how ` runSuite ` depends on ` describe ` . So, the module that imports ` runSuite `
136
+ will have to pass ` runSuite ` as the second parameter to ` describe `
137
+ like ` run ` did: ` describe('suiteName ', runSuite )` .
140
138
The export ` run ` runs the tests in the current file directly.
141
139
This is the function that is used by the test runner.
142
140
You may name it anything you want.
@@ -149,28 +147,26 @@ In this case every file would use `run`.
149
147
All the modules will have the following general structure:
150
148
151
149
``` ts
152
- import { pack , type PackageRunner } from ' https://deno.land/x/testjs/mod.ts' ;
153
- import { runModule } from ' ./suite.test.ts' ;
150
+ import { mod , type ModuleRunner } from ' https://deno.land/x/testjs/mod.ts' ;
151
+ import { runSuite } from ' ./suite.test.ts' ;
154
152
155
153
// Runs the suites in this file and imported files
156
- export const runPackage: PackageRunner = (mod ) => {
157
- mod (' moduleName' , (describe ) => {
158
- runModule (describe );
159
- // Run more suites
160
- });
154
+ export const runModule: ModuleRunner = describe => {
155
+ describe (' suiteName' , runSuite );
156
+ // Run more suites
161
157
};
162
158
163
159
export const run = () => {
164
- pack ( ' packageName ' , runPackage );
160
+ mod ( ' ModuleName ' , runModule );
165
161
};
166
162
```
167
163
168
- Here, the same pattern is used. The export ` runPackage ` runs the tests
169
- in this file. It depends on ` pack ` . It can be used by a package test file.
170
- The export ` run ` runs tests in this module and provides ` pack ` .
164
+ Here, the same pattern is used. The export ` runModule ` runs the tests
165
+ in this file. It depends on ` mod ` . It can be used by a package test file.
166
+ The export ` run ` runs tests in this module and provides ` mod ` .
171
167
It is used by the test runner to run the tests.
172
168
173
- Notice how the module imports ` runModule ` . This is the export from a test suite,
169
+ Notice how the module imports ` runSuite ` . This is the export from a test suite,
174
170
like the one described before. So, the module can run suites from other files,
175
171
and/or its own suites.
176
172
@@ -187,10 +183,10 @@ import { runViews } from './src/views/views.test.ts';
187
183
import { pack } from ' https://deno.land/x/testjs/mod.ts' ;
188
184
189
185
// Runs the modules in this file and imported files
190
- pack (' packageName' , ( mod ) => {
191
- runControllers ( mod );
192
- runModels ( mod );
193
- runViews ( mod );
186
+ pack (' packageName' , mod => {
187
+ mod ( ' Controllers ' , runControllers );
188
+ mod ( ' Models ' , runModels );
189
+ mod ( ' Views ' , runViews );
194
190
});
195
191
```
196
192
@@ -222,9 +218,9 @@ const relative = './'; // Relative path of entry directory
222
218
// Checkout run.getPaths for equivalent in Node
223
219
const absolute = new URL (relative , import .meta .url ).pathname ;
224
220
const entry = { relative , absolute };
225
- const importModule: ModuleImporter = ( path ) => import (path );
221
+ const importModule: ModuleImporter = path => import (path );
226
222
// Assuming the test files export run
227
- const getTestRunner = (mod : TestModule ): TestRunner => mod .run ;
223
+ const getTestRunner = (mod : TestModule ) => mod .run as TestRunner ;
228
224
229
225
const runTSTests = createTestRunner ({
230
226
entry ,
0 commit comments