Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .bin/test.js

This file was deleted.

7 changes: 7 additions & 0 deletions bin/japaTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Assert } from '@japa/assert'

declare module '@japa/runner' {
interface TestContext {
assert: Assert
}
}
37 changes: 37 additions & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { assert } from '@japa/assert'
import { specReporter } from '@japa/spec-reporter'
import { runFailedTests } from '@japa/run-failed-tests'
import { processCliArgs, configure, run } from '@japa/runner'

/*
|--------------------------------------------------------------------------
| Configure tests
|--------------------------------------------------------------------------
|
| The configure method accepts the configuration to configure the Japa
| tests runner.
|
| The first method call "processCliArgs" process the command line arguments
| and turns them into a config object. Using this method is not mandatory.
|
| Please consult japa.dev/runner-config for the config docs.
*/
configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['test/**/*.spec.ts'],
plugins: [assert(), runFailedTests()],
reporters: [specReporter()],
importer: (filePath: string) => import(filePath),
},
})

/*
|--------------------------------------------------------------------------
| Run tests
|--------------------------------------------------------------------------
|
| The following "run" method is required to execute all the tests.
|
*/
run()
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "cross-env FORCE_COLOR=true node .bin/test.js",
"test": "cross-env FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"lint": "eslint . --ext=.ts",
"clean": "del build",
"clean": "del-cli build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && node build/bin/index.js && copyfiles \"templates/**\" build",
"commit": "git-cz",
Expand Down Expand Up @@ -47,6 +47,10 @@
"@adonisjs/ace": "^11.2.3",
"@adonisjs/core": "^5.7.4",
"@adonisjs/mrm-preset": "^5.0.3",
"@japa/assert": "^1.3.4",
"@japa/run-failed-tests": "^1.0.7",
"@japa/runner": "^2.0.7",
"@japa/spec-reporter": "^1.1.12",
"@poppinss/dev-utils": "^2.0.3",
"@types/node": "^17.0.24",
"commitizen": "^4.2.4",
Expand All @@ -60,7 +64,6 @@
"eslint-plugin-prettier": "^4.0.0",
"github-label-sync": "^2.2.0",
"husky": "^7.0.4",
"japa": "^4.0.0",
"mrm": "^4.0.0",
"np": "^7.6.1",
"prettier": "^2.6.2",
Expand Down
38 changes: 20 additions & 18 deletions test/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

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

test.group('Compiler', (group) => {
group.before(() => {
group.setup(() => {
ui.logger.useRenderer(ui.testingRenderer)
})

group.afterEach(() => {
group.each.teardown(() => {
ui.testingRenderer.logs = []
})

group.afterEach(async () => {
group.each.teardown(async () => {
await fs.cleanup()
})

test('build source files', async (assert) => {
test('build source files', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -96,7 +96,7 @@ test.group('Compiler', (group) => {
assert.isFalse(require(join(fs.basePath, 'build', '.adonisrc.json')).typescript)
}).timeout(0)

test('build source files with explicit outDir', async (assert) => {
test('build source files with explicit outDir', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -158,7 +158,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('build source files with explicit rootDir', async (assert) => {
test('build source files with explicit rootDir', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -221,7 +221,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('build source files to nested outDir', async (assert) => {
test('build source files to nested outDir', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -284,7 +284,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('do not build when config has errors', async (assert) => {
test('do not build when config has errors', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -333,7 +333,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('catch and report typescript errors', async (assert) => {
test('catch and report typescript errors', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -401,7 +401,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('do not continue on error', async (assert) => {
test('do not continue on error', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -469,7 +469,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('do not emit when noEmitOnError is true', async (assert) => {
test('do not emit when noEmitOnError is true', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -530,7 +530,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

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

test('gracefully log error when ace file finishes with non-zero exit code', async (assert) => {
test('gracefully log error when ace file finishes with non-zero exit code', async ({
assert,
}) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -689,7 +691,7 @@ test.group('Compiler', (group) => {
assert.isFalse(require(join(fs.basePath, 'build', '.adonisrc.json')).typescript)
}).timeout(0)

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

test('build should support custom tsconfig file', async (assert) => {
test('build should support custom tsconfig file', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -795,7 +797,7 @@ test.group('Compiler', (group) => {
assert.deepEqual(hasFiles, [true, true, false])
}).timeout(0)

test('typecheck and report typescript errors', async (assert) => {
test('typecheck and report typescript errors', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down Expand Up @@ -848,7 +850,7 @@ test.group('Compiler', (group) => {
])
}).timeout(0)

test('complete successfully when typechecking has no errors', async (assert) => {
test('complete successfully when typechecking has no errors', async ({ assert }) => {
await fs.add(
'.adonisrc.json',
JSON.stringify({
Expand Down
54 changes: 27 additions & 27 deletions test/configure-encore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

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

test.group('Configure Encore', (group) => {
group.afterEach(async () => {
group.each.teardown(async () => {
await fs.cleanup()
})

test
.skipInCI('setup encore', async (assert) => {
await fs.add(
'package.json',
JSON.stringify({
name: 'sample_app',
})
)

await fs.ensureRoot()
const app = new Application(fs.basePath, 'test', {})

const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
invoke.packages = ['encore']
await invoke.run()

const envFile = await fs.fsExtra.pathExists(join(fs.basePath, 'webpack.config.js'))
const envExampleFile = await fs.fsExtra.readFile(
join(fs.basePath, 'resources/js/app.js'),
'utf-8'
)

assert.isTrue(envFile)
assert.equal(envExampleFile.trim(), '// app entrypoint')
})
test('setup encore', async ({ assert }) => {
await fs.add(
'package.json',
JSON.stringify({
name: 'sample_app',
})
)

await fs.ensureRoot()
const app = new Application(fs.basePath, 'test', {})

const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
invoke.packages = ['encore']
await invoke.run()

const envFile = await fs.fsExtra.pathExists(join(fs.basePath, 'webpack.config.js'))
const envExampleFile = await fs.fsExtra.readFile(
join(fs.basePath, 'resources/js/app.js'),
'utf-8'
)

assert.isTrue(envFile)
assert.equal(envExampleFile.trim(), '// app entrypoint')
})
.timeout(0)
.skip(!!process.env.CI)
})
50 changes: 25 additions & 25 deletions test/configure-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

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

test.group('Configure Tests', (group) => {
group.afterEach(async () => {
group.each.teardown(async () => {
await fs.cleanup()
})

test
.skipInCI('setup tests', async (assert) => {
await fs.add(
'package.json',
JSON.stringify({
name: 'sample_app',
})
)

await fs.ensureRoot()
const app = new Application(fs.basePath, 'test', {})

const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
invoke.packages = ['tests']
await invoke.run()

assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'test.ts')))
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'tests/bootstrap.ts')))
assert.isTrue(
await fs.fsExtra.pathExists(join(fs.basePath, 'tests/functional/hello_world.spec.ts'))
)
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'contracts/tests.ts')))
})
test('setup tests', async ({ assert }) => {
await fs.add(
'package.json',
JSON.stringify({
name: 'sample_app',
})
)

await fs.ensureRoot()
const app = new Application(fs.basePath, 'test', {})

const invoke = new Invoke(app, new Kernel(app).mockConsoleOutput())
invoke.packages = ['tests']
await invoke.run()

assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'test.ts')))
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'tests/bootstrap.ts')))
assert.isTrue(
await fs.fsExtra.pathExists(join(fs.basePath, 'tests/functional/hello_world.spec.ts'))
)
assert.isTrue(await fs.fsExtra.pathExists(join(fs.basePath, 'contracts/tests.ts')))
})
.timeout(0)
.skip(!!process.env.CI)
})
Loading