Set up testing with Ava
This commit is contained in:
parent
eb81cee609
commit
c3995d6fcb
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,7 @@
|
|||||||
node_modules
|
node_modules
|
||||||
site
|
site
|
||||||
docbuild
|
docbuild
|
||||||
|
__tests__
|
||||||
|
coverage
|
||||||
|
dyna3.zip
|
||||||
*~
|
*~
|
||||||
|
6
coffeetest/external.coffee
Normal file
6
coffeetest/external.coffee
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import test from 'ava'
|
||||||
|
import {three, threeLoaded} from '../site/externals.js'
|
||||||
|
|
||||||
|
test "load three", (t) ->
|
||||||
|
await threeLoaded
|
||||||
|
t.not(three, null, 'three loaded successfully')
|
3843
package-lock.json
generated
3843
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -2,25 +2,22 @@
|
|||||||
"name": "dyna3",
|
"name": "dyna3",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Constraint-based three-dimensional dynamic geometry",
|
"description": "Constraint-based three-dimensional dynamic geometry",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"main": "dyna3.js",
|
"main": "dyna3.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf site docbuild",
|
"clean": "rm -rf site docbuild dyna3.zip",
|
||||||
"doc:extra":
|
"doc:extra": "mkdir -p docbuild && coffee src/helpers/pkglock_to_externals.litcoffee --doc > docbuild/extlist.md",
|
||||||
"mkdir -p docbuild && coffee src/helpers/pkglock_to_externals.litcoffee --doc > docbuild/extlist.md",
|
"doc:collate": "mkdir -p site/doc && coffee doc/gendoc.litcoffee > site/doc/dyna3.md",
|
||||||
"doc:collate":
|
|
||||||
"mkdir -p site/doc && coffee doc/gendoc.litcoffee > site/doc/dyna3.md",
|
|
||||||
"doc": "npm run doc:extra && npm run doc:collate",
|
"doc": "npm run doc:extra && npm run doc:collate",
|
||||||
"prebuild": "npm run clean",
|
"prebuild": "npm run clean",
|
||||||
"build:coffee": "coffee -o site -c -m src/*.litcoffee",
|
"build:coffee": "coffee -o site -c -m src/*.litcoffee",
|
||||||
"build:ext":
|
"build:ext": "coffee src/helpers/pkglock_to_externals.litcoffee > site/externals.js",
|
||||||
"coffee src/helpers/pkglock_to_externals.litcoffee > site/externals.js",
|
"build:doc": "npm run doc && pandoc -s --toc site/doc/dyna3.md > site/doc/dyna3.html",
|
||||||
"build:doc":
|
|
||||||
"npm run doc && pandoc -s --toc site/doc/dyna3.md > site/doc/dyna3.html",
|
|
||||||
"build:copy": "cp src/*.html site && cp -r node_modules site",
|
"build:copy": "cp src/*.html site && cp -r node_modules site",
|
||||||
"build":
|
"build": "npm run build:coffee && npm run build:ext && npm run build:doc && npm run build:copy",
|
||||||
"npm run build:coffee && npm run build:ext && npm run build:doc && npm run build:copy",
|
"dist": "npm run build && zip -r dyna3.zip site",
|
||||||
"test": "qunit"
|
"pretest": "npm run build && coffee -o __tests__ -c -m coffeetest/*.coffee",
|
||||||
|
"test": "ava"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -35,5 +32,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"three": "latest"
|
"three": "latest"
|
||||||
},
|
},
|
||||||
"//": "See doc/tech.md for an overview of the technical structure of dyna3"
|
"//": "See doc/tech.md for an overview of the technical structure of dyna3",
|
||||||
|
"devDependencies": {
|
||||||
|
"ava": "^2.4.0",
|
||||||
|
"esm": "^3.2.25"
|
||||||
|
},
|
||||||
|
"ava": {
|
||||||
|
"require": [
|
||||||
|
"esm"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,23 @@ When you load dyna3, you should initially see a three-dimensional coordinate sys
|
|||||||
|
|
||||||
import {threeLoaded, three as J3} from './externals.js'
|
import {threeLoaded, three as J3} from './externals.js'
|
||||||
|
|
||||||
main = () ->
|
main = ->
|
||||||
renderer = new J3.WebGLRenderer()
|
renderer = new J3.WebGLRenderer()
|
||||||
rwd = window.innerWidth
|
rwd = window.innerWidth
|
||||||
rht = window.innerHeight
|
rht = window.innerHeight
|
||||||
renderer.setSize(rwd, rht)
|
renderer.setSize rwd, rht
|
||||||
document.body.appendChild renderer.domElement
|
document.body.appendChild renderer.domElement
|
||||||
|
|
||||||
scene = new J3.Scene()
|
scene = new J3.Scene()
|
||||||
geometry = new J3.SphereBufferGeometry(1, 5, 5)
|
geometry = new J3.SphereBufferGeometry 1,5,5
|
||||||
material = new J3.MeshBasicMaterial {color: 0xff00ff}
|
material = new J3.MeshBasicMaterial {color: 0xff00ff}
|
||||||
ball = new J3.Mesh(geometry, material)
|
ball = new J3.Mesh geometry, material
|
||||||
scene.add ball
|
scene.add ball
|
||||||
|
|
||||||
camera = new J3.PerspectiveCamera(75, rwd/rht, 0.1, 1000)
|
camera = new J3.PerspectiveCamera 75, rwd/rht, 0.1, 1000
|
||||||
camera.position.z = 5
|
camera.position.z = 5
|
||||||
|
|
||||||
renderer.render(scene, camera)
|
renderer.render scene, camera
|
||||||
|
|
||||||
threeLoaded.then(main)
|
threeLoaded.then main
|
||||||
```
|
```
|
||||||
|
@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
### External dependencies
|
### External dependencies
|
||||||
|
|
||||||
The dyna3 program depends on some externally-maintained JavaScript libraries/modules. The package uses npm to track these external dependencies. A module externals.js is automatically generated from the package_lock.json file created by npm to load the necessary modules at runtime.
|
The dyna3 program depends on some externally-maintained JavaScript libraries/modules. The package uses npm to track these external dependencies. A module externals.js is automatically generated from the package.json and package_lock.json files created by npm to load the necessary modules at runtime.
|
||||||
|
|
||||||
The generation is performed by pkglock_to_externals.litcoffee, which also records the main importable file within the library, as there does not seem to be a systematic way to generate that filename from the module name.
|
The generation is performed by pkglock_to_externals.litcoffee, which also records the main importable file within the library, as there does not seem to be a systematic way to generate that filename from the module name.
|
||||||
|
|
||||||
Specific packages/implementation approaches for components of dyna3 include the following items. All packages are obtained from npm unless otherwise noted.
|
Specific packages/implementation approaches for components of dyna3 include the following items. All packages are obtained from npm unless otherwise noted.
|
||||||
|
|
||||||
- for conversion of markdown to HTML: pandoc
|
- for conversion of markdown to HTML: pandoc
|
||||||
- For a test harness for the package: QUnit
|
- For a test harness for the package: Ava
|
||||||
|
- When a point is reached at which there is a need to test in-browser behavior, ava can call Puppeteer as per https://github.com/avajs/ava/blob/master/docs/recipes/puppeteer.md
|
||||||
- For WebGL rendering of the 3D view of the geometry: three
|
- For WebGL rendering of the 3D view of the geometry: three
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@ -31,9 +32,9 @@ And here is the current complete list of external libraries on which operation o
|
|||||||
"""
|
"""
|
||||||
process.stdout.write header
|
process.stdout.write header
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
pl = fs.readFileSync 'package-lock.json'
|
pkdata = JSON.parse fs.readFileSync 'package.json'
|
||||||
pdata = JSON.parse pl
|
pldata = JSON.parse fs.readFileSync 'package-lock.json'
|
||||||
for dep in Object.keys pdata.dependencies
|
for dep in Object.keys pkdata.dependencies
|
||||||
if process.argv.length > 2
|
if process.argv.length > 2
|
||||||
process.stdout.write "- #{dep}\n"
|
process.stdout.write "- #{dep}\n"
|
||||||
else
|
else
|
||||||
@ -43,10 +44,11 @@ And here is the current complete list of external libraries on which operation o
|
|||||||
export var #{dep}Loaded = new Promise(async function(resolve, reject) {
|
export var #{dep}Loaded = new Promise(async function(resolve, reject) {
|
||||||
var success = false;
|
var success = false;
|
||||||
try {
|
try {
|
||||||
#{dep} = await import('https://cdn.jsdelivr.net/npm/#{dep}@#{pdata.dependencies[dep].version}/#{importable[dep]}');
|
#{dep} = await import('https://cdn.jsdelivr.net/npm/#{dep}@#{pldata.dependencies[dep].version}/#{importable[dep]}');
|
||||||
console.log('CDN import of #{dep} module OK');
|
console.log('CDN import of #{dep} module OK');
|
||||||
success = true;
|
success = true;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
console.log('CDN import of #{dep} failed: ' + JSON.stringify(err));
|
||||||
try {
|
try {
|
||||||
#{dep} = await import('./node_modules/#{dep}/#{importable[dep]}');
|
#{dep} = await import('./node_modules/#{dep}/#{importable[dep]}');
|
||||||
success = true;
|
success = true;
|
||||||
@ -56,7 +58,6 @@ And here is the current complete list of external libraries on which operation o
|
|||||||
}
|
}
|
||||||
if (success) { resolve(); } else { reject(); }
|
if (success) { resolve(); } else { reject(); }
|
||||||
});
|
});
|
||||||
|
|
||||||
"""
|
"""
|
||||||
process.stdout.write block
|
process.stdout.write block
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user