Skip to content

Commit 2fa8b0f

Browse files
authored
Merge pull request #9 from test-bdd/dev
Fix directory read
2 parents 0c73892 + 66ed641 commit 2fa8b0f

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

docs/test-runner.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,29 @@ Let us start from the bottom. The suites will have test files
112112
with the following general structure:
113113

114114
```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';
116116
import { testSubject } from './test-subject.ts';
117117

118118
// 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());
125123
});
126124
};
127125

128126
export const run = () => {
129-
mod('moduleName', runModule);
127+
describe('suiteName', runSuite);
130128
};
131129
```
132130

133131
For example, the test file for `email.test.ts` imports its test subjects
134132
from `email.ts`. The `testSubject` may be a function that checks if an email
135133
has the correct format. The `toDoSomething` function may be the `toMatch` assertion.
136134

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)`.
140138
The export `run` runs the tests in the current file directly.
141139
This is the function that is used by the test runner.
142140
You may name it anything you want.
@@ -149,28 +147,26 @@ In this case every file would use `run`.
149147
All the modules will have the following general structure:
150148

151149
```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';
154152

155153
// 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
161157
};
162158

163159
export const run = () => {
164-
pack('packageName', runPackage);
160+
mod('ModuleName', runModule);
165161
};
166162
```
167163

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`.
171167
It is used by the test runner to run the tests.
172168

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,
174170
like the one described before. So, the module can run suites from other files,
175171
and/or its own suites.
176172

@@ -187,10 +183,10 @@ import { runViews } from './src/views/views.test.ts';
187183
import { pack } from 'https://deno.land/x/testjs/mod.ts';
188184

189185
// 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);
194190
});
195191
```
196192

@@ -222,9 +218,9 @@ const relative = './'; // Relative path of entry directory
222218
// Checkout run.getPaths for equivalent in Node
223219
const absolute = new URL(relative, import.meta.url).pathname;
224220
const entry = { relative, absolute };
225-
const importModule: ModuleImporter = (path) => import(path);
221+
const importModule: ModuleImporter = path => import(path);
226222
// Assuming the test files export run
227-
const getTestRunner = (mod: TestModule): TestRunner => mod.run;
223+
const getTestRunner = (mod: TestModule) => mod.run as TestRunner;
228224

229225
const runTSTests = createTestRunner({
230226
entry,

lib/run-tests/get-paths.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { readDir } = Deno;
88

99
const matchFile =
1010
(regex: RegExp): FileMatcher =>
11-
(path) => {
11+
path => {
1212
return regex.test(path);
1313
};
1414

@@ -122,12 +122,16 @@ export const getPaths = (isMatch: FileMatcher): PathGetter => {
122122
return paths;
123123
}
124124

125-
const dirEntries = readDir(path);
125+
try {
126+
const dirEntries = readDir(path);
126127

127-
for await (const entry of dirEntries) {
128-
if (entry.isFile || entry.isDirectory) {
129-
paths = await get(`${path}/${entry.name}`, paths);
128+
for await (const entry of dirEntries) {
129+
if (entry.isFile || entry.isDirectory) {
130+
paths = await get(`${path}/${entry.name}`, paths);
131+
}
130132
}
133+
} catch (error) {
134+
console.error(error);
131135
}
132136

133137
return paths;

0 commit comments

Comments
 (0)