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

Add testing setup #5

Merged
merged 5 commits into from
Feb 22, 2024
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
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
"build": "webpack --mode production",
"test": "vitest"
},
"files": [
"dist",
Expand All @@ -24,9 +25,20 @@
"vue": "^3.3.13"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"@vitest/browser": "^1.3.0",
"@vue/compiler-sfc": "^3.3.13",
"@vue/test-utils": "^2.4.4",
"mock-require": "^3.0.3",
"phaser": "^3.70.0",
"vitest": "^1.3.0",
"vue": "^3.3.13",
"vue-loader": "^17.3.1",
"webdriverio": "^8.32.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"resolutions": {
"jackspeak": "2.1.1"
}
}
14 changes: 8 additions & 6 deletions src/components/Game.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export default defineComponent({
config: { type: Object }
},
setup (props, context) {
console.log(
`%c %cPhavuer v${packageJson.version}%c https://github.com/laineus/phavuer`,
'background-color: #42b883; padding: 2px 0;',
'background-color: #213547; padding: 2px 8px; color: white; font-weight: bold;',
''
)
if (props.config?.banner !== false) {
console.log(
`%c %cPhavuer v${packageJson.version}%c https://github.com/laineus/phavuer`,
'background-color: #42b883; padding: 2px 0;',
'background-color: #213547; padding: 2px 8px; color: white; font-weight: bold;',
''
)
}
const canvasRoot = ref(false)
const show = ref(false)
onMounted(() => {
Expand Down
44 changes: 44 additions & 0 deletions src/components/__tests__/Game.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import Game from '../Game.vue'

describe('Game', () => {
/**
* @type {import('phaser').Types.Core.GameConfig}
*/
const config = {
/**
* Prevent the Phaser & Phavuer banner from polluting the test logs
*/
banner: false,
};

it('emits the create event', () => {
const wrapper = mount(Game, {
props: {
config,
},
})
expect(wrapper.emitted().create).toBeTruthy()
})

it('appends a canvas element to the [data-phavuer-canvas]', () => {
const wrapper = mount(Game, {
props: {
config,
},
})
expect(wrapper.find('[data-phavuer-canvas] > canvas').exists()).toBe(true)
})

it('emits the ready event', async () => {
vi.useFakeTimers();
const wrapper = mount(Game, {
props: {
config,
},
})
await vi.runOnlyPendingTimersAsync()
expect(wrapper.emitted().ready).toBeTruthy()
})
})
22 changes: 22 additions & 0 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
plugins: [vue()],
test: {
browser: {
/**
* `name` is required
*/
name: 'chrome',
enabled: true,
providerOptions: {
logLevel: 'silent', logLevels: { webdriver: 'silent' }
},
},
setupFiles: [
'./vitest.setup.mjs',
],
},
})
1 change: 1 addition & 0 deletions vitest.setup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'phaser'
Loading