Skip to content

Commit 06fd6a6

Browse files
authored
refactor: migrate to the latest Japa version (#47)
* refactor: migrate to latest japa version * style: lint fix * Revert "style: lint fix" This reverts commit 49a465c. * style: lint fix
1 parent 09d2b81 commit 06fd6a6

20 files changed

+211
-169
lines changed

.bin/test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

bin/japaTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Assert } from '@japa/assert'
2+
3+
declare module '@japa/runner' {
4+
interface TestContext {
5+
assert: Assert
6+
}
7+
}

bin/test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { assert } from '@japa/assert'
2+
import { specReporter } from '@japa/spec-reporter'
3+
import { runFailedTests } from '@japa/run-failed-tests'
4+
import { processCliArgs, configure, run } from '@japa/runner'
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Configure tests
9+
|--------------------------------------------------------------------------
10+
|
11+
| The configure method accepts the configuration to configure the Japa
12+
| tests runner.
13+
|
14+
| The first method call "processCliArgs" process the command line arguments
15+
| and turns them into a config object. Using this method is not mandatory.
16+
|
17+
| Please consult japa.dev/runner-config for the config docs.
18+
*/
19+
configure({
20+
...processCliArgs(process.argv.slice(2)),
21+
...{
22+
files: ['test/**/*.spec.ts'],
23+
plugins: [assert(), runFailedTests()],
24+
reporters: [specReporter()],
25+
importer: (filePath: string) => import(filePath),
26+
},
27+
})
28+
29+
/*
30+
|--------------------------------------------------------------------------
31+
| Run tests
32+
|--------------------------------------------------------------------------
33+
|
34+
| The following "run" method is required to execute all the tests.
35+
|
36+
*/
37+
run()

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"scripts": {
1616
"mrm": "mrm --preset=@adonisjs/mrm-preset",
1717
"pretest": "npm run lint",
18-
"test": "cross-env FORCE_COLOR=true node .bin/test.js",
18+
"test": "cross-env FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
1919
"lint": "eslint . --ext=.ts",
20-
"clean": "del build",
20+
"clean": "del-cli build",
2121
"compile": "npm run lint && npm run clean && tsc",
2222
"build": "npm run compile && node build/bin/index.js && copyfiles \"templates/**\" build",
2323
"commit": "git-cz",
@@ -47,6 +47,10 @@
4747
"@adonisjs/ace": "^11.2.3",
4848
"@adonisjs/core": "^5.7.4",
4949
"@adonisjs/mrm-preset": "^5.0.3",
50+
"@japa/assert": "^1.3.4",
51+
"@japa/run-failed-tests": "^1.0.7",
52+
"@japa/runner": "^2.0.7",
53+
"@japa/spec-reporter": "^1.1.12",
5054
"@poppinss/dev-utils": "^2.0.3",
5155
"@types/node": "^17.0.24",
5256
"commitizen": "^4.2.4",
@@ -60,7 +64,6 @@
6064
"eslint-plugin-prettier": "^4.0.0",
6165
"github-label-sync": "^2.2.0",
6266
"husky": "^7.0.4",
63-
"japa": "^4.0.0",
6467
"mrm": "^4.0.0",
6568
"np": "^7.6.1",
6669
"prettier": "^2.6.2",

test/compiler.spec.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import test from 'japa'
10+
import { test } from '@japa/runner'
1111
import execa from 'execa'
1212
import { join } from 'path'
1313
import { Filesystem } from '@poppinss/dev-utils'
@@ -20,19 +20,19 @@ const ui = instantiate(true)
2020
const fs = new Filesystem(join(__dirname, '__app'))
2121

2222
test.group('Compiler', (group) => {
23-
group.before(() => {
23+
group.setup(() => {
2424
ui.logger.useRenderer(ui.testingRenderer)
2525
})
2626

27-
group.afterEach(() => {
27+
group.each.teardown(() => {
2828
ui.testingRenderer.logs = []
2929
})
3030

31-
group.afterEach(async () => {
31+
group.each.teardown(async () => {
3232
await fs.cleanup()
3333
})
3434

35-
test('build source files', async (assert) => {
35+
test('build source files', async ({ assert }) => {
3636
await fs.add(
3737
'.adonisrc.json',
3838
JSON.stringify({
@@ -96,7 +96,7 @@ test.group('Compiler', (group) => {
9696
assert.isFalse(require(join(fs.basePath, 'build', '.adonisrc.json')).typescript)
9797
}).timeout(0)
9898

99-
test('build source files with explicit outDir', async (assert) => {
99+
test('build source files with explicit outDir', async ({ assert }) => {
100100
await fs.add(
101101
'.adonisrc.json',
102102
JSON.stringify({
@@ -158,7 +158,7 @@ test.group('Compiler', (group) => {
158158
])
159159
}).timeout(0)
160160

161-
test('build source files with explicit rootDir', async (assert) => {
161+
test('build source files with explicit rootDir', async ({ assert }) => {
162162
await fs.add(
163163
'.adonisrc.json',
164164
JSON.stringify({
@@ -221,7 +221,7 @@ test.group('Compiler', (group) => {
221221
])
222222
}).timeout(0)
223223

224-
test('build source files to nested outDir', async (assert) => {
224+
test('build source files to nested outDir', async ({ assert }) => {
225225
await fs.add(
226226
'.adonisrc.json',
227227
JSON.stringify({
@@ -284,7 +284,7 @@ test.group('Compiler', (group) => {
284284
])
285285
}).timeout(0)
286286

287-
test('do not build when config has errors', async (assert) => {
287+
test('do not build when config has errors', async ({ assert }) => {
288288
await fs.add(
289289
'.adonisrc.json',
290290
JSON.stringify({
@@ -333,7 +333,7 @@ test.group('Compiler', (group) => {
333333
])
334334
}).timeout(0)
335335

336-
test('catch and report typescript errors', async (assert) => {
336+
test('catch and report typescript errors', async ({ assert }) => {
337337
await fs.add(
338338
'.adonisrc.json',
339339
JSON.stringify({
@@ -401,7 +401,7 @@ test.group('Compiler', (group) => {
401401
])
402402
}).timeout(0)
403403

404-
test('do not continue on error', async (assert) => {
404+
test('do not continue on error', async ({ assert }) => {
405405
await fs.add(
406406
'.adonisrc.json',
407407
JSON.stringify({
@@ -469,7 +469,7 @@ test.group('Compiler', (group) => {
469469
])
470470
}).timeout(0)
471471

472-
test('do not emit when noEmitOnError is true', async (assert) => {
472+
test('do not emit when noEmitOnError is true', async ({ assert }) => {
473473
await fs.add(
474474
'.adonisrc.json',
475475
JSON.stringify({
@@ -530,7 +530,7 @@ test.group('Compiler', (group) => {
530530
])
531531
}).timeout(0)
532532

533-
test('build for production should copy package files to build folder', async (assert) => {
533+
test('build for production should copy package files to build folder', async ({ assert }) => {
534534
await fs.add(
535535
'.adonisrc.json',
536536
JSON.stringify({
@@ -618,7 +618,9 @@ test.group('Compiler', (group) => {
618618
assert.isTrue(hasPackageLock)
619619
}).timeout(0)
620620

621-
test('gracefully log error when ace file finishes with non-zero exit code', async (assert) => {
621+
test('gracefully log error when ace file finishes with non-zero exit code', async ({
622+
assert,
623+
}) => {
622624
await fs.add(
623625
'.adonisrc.json',
624626
JSON.stringify({
@@ -689,7 +691,7 @@ test.group('Compiler', (group) => {
689691
assert.isFalse(require(join(fs.basePath, 'build', '.adonisrc.json')).typescript)
690692
}).timeout(0)
691693

692-
test('ignore error when any of the meta file is missing', async (assert) => {
694+
test('ignore error when any of the meta file is missing', async ({ assert }) => {
693695
await fs.add(
694696
'.adonisrc.json',
695697
JSON.stringify({
@@ -744,7 +746,7 @@ test.group('Compiler', (group) => {
744746
assert.isFalse(require(join(fs.basePath, 'build', '.adonisrc.json')).typescript)
745747
}).timeout(0)
746748

747-
test('build should support custom tsconfig file', async (assert) => {
749+
test('build should support custom tsconfig file', async ({ assert }) => {
748750
await fs.add(
749751
'.adonisrc.json',
750752
JSON.stringify({
@@ -795,7 +797,7 @@ test.group('Compiler', (group) => {
795797
assert.deepEqual(hasFiles, [true, true, false])
796798
}).timeout(0)
797799

798-
test('typecheck and report typescript errors', async (assert) => {
800+
test('typecheck and report typescript errors', async ({ assert }) => {
799801
await fs.add(
800802
'.adonisrc.json',
801803
JSON.stringify({
@@ -848,7 +850,7 @@ test.group('Compiler', (group) => {
848850
])
849851
}).timeout(0)
850852

851-
test('complete successfully when typechecking has no errors', async (assert) => {
853+
test('complete successfully when typechecking has no errors', async ({ assert }) => {
852854
await fs.add(
853855
'.adonisrc.json',
854856
JSON.stringify({

test/configure-encore.spec.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import test from 'japa'
10+
import { test } from '@japa/runner'
1111
import { join } from 'path'
1212
import { Kernel } from '@adonisjs/ace'
1313
import { Filesystem } from '@poppinss/dev-utils'
@@ -18,34 +18,34 @@ import Invoke from '../commands/Invoke'
1818
const fs = new Filesystem(join(__dirname, '__app'))
1919

2020
test.group('Configure Encore', (group) => {
21-
group.afterEach(async () => {
21+
group.each.teardown(async () => {
2222
await fs.cleanup()
2323
})
2424

25-
test
26-
.skipInCI('setup encore', async (assert) => {
27-
await fs.add(
28-
'package.json',
29-
JSON.stringify({
30-
name: 'sample_app',
31-
})
32-
)
33-
34-
await fs.ensureRoot()
35-
const app = new Application(fs.basePath, 'test', {})
36-
37-
const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
38-
invoke.packages = ['encore']
39-
await invoke.run()
40-
41-
const envFile = await fs.fsExtra.pathExists(join(fs.basePath, 'webpack.config.js'))
42-
const envExampleFile = await fs.fsExtra.readFile(
43-
join(fs.basePath, 'resources/js/app.js'),
44-
'utf-8'
45-
)
46-
47-
assert.isTrue(envFile)
48-
assert.equal(envExampleFile.trim(), '// app entrypoint')
49-
})
25+
test('setup encore', async ({ assert }) => {
26+
await fs.add(
27+
'package.json',
28+
JSON.stringify({
29+
name: 'sample_app',
30+
})
31+
)
32+
33+
await fs.ensureRoot()
34+
const app = new Application(fs.basePath, 'test', {})
35+
36+
const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
37+
invoke.packages = ['encore']
38+
await invoke.run()
39+
40+
const envFile = await fs.fsExtra.pathExists(join(fs.basePath, 'webpack.config.js'))
41+
const envExampleFile = await fs.fsExtra.readFile(
42+
join(fs.basePath, 'resources/js/app.js'),
43+
'utf-8'
44+
)
45+
46+
assert.isTrue(envFile)
47+
assert.equal(envExampleFile.trim(), '// app entrypoint')
48+
})
5049
.timeout(0)
50+
.skip(!!process.env.CI)
5151
})

test/configure-tests.spec.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import test from 'japa'
10+
import { test } from '@japa/runner'
1111
import { join } from 'path'
1212
import { Kernel } from '@adonisjs/ace'
1313
import { Filesystem } from '@poppinss/dev-utils'
@@ -18,32 +18,32 @@ import Invoke from '../commands/Invoke'
1818
const fs = new Filesystem(join(__dirname, '__app'))
1919

2020
test.group('Configure Tests', (group) => {
21-
group.afterEach(async () => {
21+
group.each.teardown(async () => {
2222
await fs.cleanup()
2323
})
2424

25-
test
26-
.skipInCI('setup tests', async (assert) => {
27-
await fs.add(
28-
'package.json',
29-
JSON.stringify({
30-
name: 'sample_app',
31-
})
32-
)
33-
34-
await fs.ensureRoot()
35-
const app = new Application(fs.basePath, 'test', {})
36-
37-
const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
38-
invoke.packages = ['tests']
39-
await invoke.run()
40-
41-
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'test.ts')))
42-
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'tests/bootstrap.ts')))
43-
assert.isTrue(
44-
await fs.fsExtra.pathExists(join(fs.basePath, 'tests/functional/hello_world.spec.ts'))
45-
)
46-
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'contracts/tests.ts')))
47-
})
25+
test('setup tests', async ({ assert }) => {
26+
await fs.add(
27+
'package.json',
28+
JSON.stringify({
29+
name: 'sample_app',
30+
})
31+
)
32+
33+
await fs.ensureRoot()
34+
const app = new Application(fs.basePath, 'test', {})
35+
36+
const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
37+
invoke.packages = ['tests']
38+
await invoke.run()
39+
40+
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'test.ts')))
41+
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'tests/bootstrap.ts')))
42+
assert.isTrue(
43+
await fs.fsExtra.pathExists(join(fs.basePath, 'tests/functional/hello_world.spec.ts'))
44+
)
45+
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'contracts/tests.ts')))
46+
})
4847
.timeout(0)
48+
.skip(!!process.env.CI)
4949
})

0 commit comments

Comments
 (0)