Skip to content

Commit

Permalink
test: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Oct 7, 2023
1 parent 5a1e47c commit f5d2893
Show file tree
Hide file tree
Showing 38 changed files with 819 additions and 10,967 deletions.
32 changes: 28 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
name: test
on: [push]
jobs:
test:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true
- uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- run: pnpm lint

test-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true
- uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- run: pnpm test:integration

- run: pnpm lint
- run: pnpm t
test-e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: true
- uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- run: pnpm test:e2e
176 changes: 1 addition & 175 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,176 +1,2 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store

test-results
8 changes: 8 additions & 0 deletions demo/demo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* {
margin: 0;
padding: 0;
}

.container {
padding-bottom: 10px 0;
}
68 changes: 68 additions & 0 deletions demo/demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Nostalgist } from '../src'

let nostalgist: Nostalgist
let state: Awaited<ReturnType<Nostalgist['saveState']>>

async function nes() {
nostalgist = await Nostalgist.nes('pong1k.nes')
}

async function megadrive() {
nostalgist = await Nostalgist.megadrive('asciiwar.bin')
}

async function gbc() {
nostalgist = await Nostalgist.gbc('combatsoccer.gbc')
}

async function launch() {
nostalgist = await Nostalgist.launch({ core: 'nestopia', rom: 'pong1k.nes' })
}

async function saveState() {
state = await nostalgist.saveState()
}

async function loadState() {
await nostalgist.loadState(state.state)
}

function pause() {
nostalgist.pause()
}

function resume() {
nostalgist.resume()
}

function restart() {
nostalgist.restart()
}

function resize() {
nostalgist.resize(400, 400)
}

document.body.addEventListener('click', async function listener({ target }) {
if (!(target instanceof HTMLButtonElement)) {
return
}
const handlers = {
nes,
megadrive,
gbc,
launch,
saveState,
loadState,
pause,
resume,
restart,
resize,
}
const textContent = target.textContent || ''
if (textContent in handlers) {
const handler = handlers[textContent]
await handler()
target.blur()
}
})
28 changes: 28 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nostalgist.js demo page</title>
<link rel="icon" type="image/png" href="https://js.org/favicon.png" />
<link rel="stylesheet" href="./demo.css" />
</head>
<body>
<div class="container">
<h3>static methods</h3>
<button type="button">nes</button>
<button type="button">megadrive</button>
<button type="button">gbc</button>
<button type="button">launchNestopia</button>
<h3>instance methods</h3>
<button type="button">saveState</button>
<button type="button">loadState</button>
<button type="button">pause</button>
<button type="button">resume</button>
<button type="button">restart</button>
<button type="button">resize</button>
</div>
<br />
<script type="module" src="./demo.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/index.ts → demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function runExample2() {
const nostalgist = await Nostalgist.megadrive('astroperdido.bin')
await new Promise((resolve) => setTimeout(resolve, 1000))
const state = await nostalgist.saveState()
console.log(state)
console.info(state)
}

async function runExample3() {
Expand Down
Loading

0 comments on commit f5d2893

Please sign in to comment.