-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate more unit tests from Karma to Node (#4163)
- Loading branch information
1 parent
c696df8
commit 3156030
Showing
14 changed files
with
731 additions
and
1,083 deletions.
There are no files selected for viewing
193 changes: 101 additions & 92 deletions
193
...k/components/model/test_modelcomponent.js → ...ework/components/model/component.test.mjs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { http, Http } from '../../src/net/http.js'; | ||
|
||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
describe('Http', function () { | ||
let retryDelay; | ||
|
||
beforeEach(function () { | ||
retryDelay = Http.retryDelay; | ||
Http.retryDelay = 1; | ||
}); | ||
|
||
afterEach(function () { | ||
Http.retryDelay = retryDelay; | ||
sinon.restore(); | ||
}); | ||
|
||
describe('#get()', function () { | ||
|
||
it('returns resource', function (done) { | ||
http.get('http://localhost:3000/test/test-assets/test.json', function (err, data) { | ||
expect(err).to.equal(null); | ||
expect(data).to.deep.equal({ | ||
a: 1, | ||
b: true, | ||
c: 'hello world' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('does not retry if retry is false', function (done) { | ||
sinon.spy(http, 'request'); | ||
http.get('http://localhost:3000/someurl.json', function (err, data) { | ||
expect(err).to.equal(404); | ||
expect(http.request.callCount).to.equal(1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('retries resource and returns 404 in the end if not found', function (done) { | ||
sinon.spy(http, 'request'); | ||
http.get('http://localhost:3000/someurl.json', { | ||
retry: true, | ||
maxRetries: 2 | ||
}, function (err) { | ||
expect(err).to.equal(404); | ||
expect(http.request.callCount).to.equal(3); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('retries resource 5 times by default', function (done) { | ||
sinon.spy(http, 'request'); | ||
http.get('http://localhost:3000/someurl.json', { | ||
retry: true | ||
}, function (err) { | ||
expect(http.request.callCount).to.equal(6); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Application } from '../../../src/framework/app-base.js'; | ||
import { Entity } from '../../../src/framework/entity.js'; | ||
import { LAYERID_WORLD } from '../../../src/scene/constants.js'; | ||
|
||
import { HTMLCanvasElement } from '@playcanvas/canvas-mock'; | ||
|
||
import { expect } from 'chai'; | ||
|
||
describe('BatchManager', function () { | ||
|
||
beforeEach(function () { | ||
const canvas = new HTMLCanvasElement(500, 500); | ||
this.app = new Application(canvas); | ||
|
||
this.bg = this.app.batcher.addGroup('Test Group', false, 100); | ||
}); | ||
|
||
afterEach(function () { | ||
this.app.destroy(); | ||
}); | ||
|
||
it('generate: removes model component mesh instances from layer', function () { | ||
const e1 = new Entity(); | ||
e1.name = 'e1'; | ||
e1.addComponent('model', { | ||
type: 'box', | ||
batchGroupId: this.bg.id | ||
}); | ||
|
||
const e2 = new Entity(); | ||
e2.name = 'e2'; | ||
e2.addComponent('model', { | ||
type: 'box', | ||
batchGroupId: this.bg.id | ||
}); | ||
|
||
this.app.root.addChild(e1); | ||
this.app.root.addChild(e2); | ||
|
||
this.app.batcher.generate(); | ||
|
||
const layer = this.app.scene.layers.getLayerById(LAYERID_WORLD); | ||
const instances = layer.opaqueMeshInstances; | ||
|
||
expect(instances.length).to.equal(1); | ||
expect(instances[0]).not.to.equal(e1.model.meshInstances[0]); | ||
expect(instances[1]).not.to.equal(e2.model.meshInstances[0]); | ||
}); | ||
|
||
it('disable model component, marks batch group dirty', function () { | ||
const e1 = new Entity(); | ||
e1.name = 'e1'; | ||
e1.addComponent('model', { | ||
type: 'box', | ||
batchGroupId: this.bg.id | ||
}); | ||
|
||
const e2 = new Entity(); | ||
e2.name = 'e2'; | ||
e2.addComponent('model', { | ||
type: 'box', | ||
batchGroupId: this.bg.id | ||
}); | ||
|
||
this.app.root.addChild(e1); | ||
this.app.root.addChild(e2); | ||
|
||
this.app.batcher.generate(); | ||
|
||
e2.enabled = false; | ||
|
||
expect(this.app.batcher._dirtyGroups[0]).to.equal(this.bg.id); | ||
}); | ||
|
||
|
||
it('batch with all invisible meshinstances works', function () { | ||
const e1 = new Entity(); | ||
e1.name = 'e1'; | ||
e1.addComponent('model', { | ||
type: 'box', | ||
batchGroupId: this.bg.id | ||
}); | ||
|
||
const e2 = new Entity(); | ||
e2.name = 'e2'; | ||
e2.addComponent('model', { | ||
type: 'box', | ||
batchGroupId: this.bg.id | ||
}); | ||
|
||
|
||
e1.model.meshInstances[0].visible = false; | ||
e2.model.meshInstances[0].visible = false; | ||
|
||
this.app.root.addChild(e1); | ||
this.app.root.addChild(e2); | ||
|
||
this.app.batcher.generate(); | ||
|
||
expect(this.app.batcher._batchList.length).to.equal(0); | ||
|
||
}); | ||
}); |
Oops, something went wrong.