Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for minimal implementation #20

Merged
merged 3 commits into from
Sep 27, 2022
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
18 changes: 18 additions & 0 deletions tests/e2e/minimal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @vitest-environment node
*/
import { fileURLToPath } from 'node:url'
import { describe } from 'vitest'
import { setup } from '@nuxt/test-utils'

import runTests from './tests'

describe('Minimal implementation of the module', async () => {
await setup({
server: true,
browser: true,
rootDir: fileURLToPath(new URL('../fixture/minimal', import.meta.url))
})

runTests()
})
18 changes: 18 additions & 0 deletions tests/e2e/regular.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @vitest-environment node
*/
import { fileURLToPath } from 'node:url'
import { describe } from 'vitest'
import { setup } from '@nuxt/test-utils'

import runTests from './tests'

describe('Regular implementation of the module', async () => {
await setup({
server: true,
browser: true,
rootDir: fileURLToPath(new URL('../fixture/regular', import.meta.url))
})

runTests()
})
30 changes: 13 additions & 17 deletions tests/e2e/ssr.test.ts → tests/e2e/tests.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/**
* @vitest-environment node
*/
import { fileURLToPath } from 'node:url'
import { describe, test, expect } from 'vitest'
import { setup, createPage } from '@nuxt/test-utils'

describe('ssr', async () => {
await setup({
server: true,
browser: true,
rootDir: fileURLToPath(new URL('../fixture', import.meta.url))
})
import { test, expect } from 'vitest'
import { createPage } from '@nuxt/test-utils'

export default function () {
test('shows proper state before clicking', async () => {
const page = await createPage('/')

Expand All @@ -28,7 +18,13 @@ describe('ssr', async () => {
expect(stateText).toBe('loading')
})

// test('auto-imports state machine correctly', () => {
// expect(1 + 1).toBe(2)
// })
})
test('auto-imported state machine works correctly', async () => {
const page = await createPage('/')

const machineString = await page.innerText('[data-test-id="machine"]')
const machine = JSON.parse(machineString)

// TODO: Add more (possibly complex) test cases
expect(machine.state).not.toBe(undefined)
})
}
6 changes: 5 additions & 1 deletion tests/fixture/app.vue → tests/fixture/minimal/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
<button data-test-id="click-btn" @click="send('CLICK')">
CLICK
</button>
<p data-test-id="machine">
{{ machine }}
</p>
</div>
</template>

<script setup>
const { state, send } = useMachine(loadingMachine)
const machine = useMachine(loadingMachine)
const { state, send } = machine
</script>
13 changes: 13 additions & 0 deletions tests/fixture/minimal/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineNuxtConfig } from 'nuxt/config'
import XStateModule from '../../../'

// Fixture module used mostly for testing when using the minimal option
export default defineNuxtConfig({
modules: [
// @ts-ignore-next-line
XStateModule
],
xState: {
minimal: true
}
})
9 changes: 0 additions & 9 deletions tests/fixture/nuxt.config.ts

This file was deleted.

16 changes: 16 additions & 0 deletions tests/fixture/regular/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<h1>Current state: <span data-test-id="state-txt">{{ state.value }}</span></h1>
<button data-test-id="click-btn" @click="send('CLICK')">
CLICK
</button>
<p data-test-id="machine">
{{ machine }}
</p>
</div>
</template>

<script setup>
const machine = useMachine(loadingMachine)
const { state, send } = machine
</script>
17 changes: 17 additions & 0 deletions tests/fixture/regular/machines/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default createMachine({
id: 'loading',
initial: 'idle',
predictableActionArguments: true,
states: {
idle: {
on: {
CLICK: 'loading'
}
},
loading: {
on: {
CLICK: 'idle'
}
}
}
})
13 changes: 13 additions & 0 deletions tests/fixture/regular/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineNuxtConfig } from 'nuxt/config'
import XStateModule from '../../../'

// Fixture module used mostly for testing when using the minimal option
export default defineNuxtConfig({
modules: [
// @ts-ignore-next-line
XStateModule
],
xState: {
minimal: false
}
})
5 changes: 5 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"github": {
"silent": true
}
}
4 changes: 2 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
deps: {
inline: [/@nuxt\/test-utils-edge/]
inline: [/@nuxt\/test-utils/]
},
testTimeout: 10000
testTimeout: 15000
}
})