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

Tidy up Karma tests #6175

Merged
merged 3 commits into from
Mar 16, 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
41 changes: 40 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@
"global-jsdom": "^24.0.0",
"jsdom": "^24.0.0",
"karma": "^6.4.3",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.2.0",
"karma-mocha": "2.0.1",
"karma-mocha": "^2.0.1",
"karma-sinon": "^1.0.5",
"karma-spec-reporter": "^0.0.36",
"mocha": "^10.3.0",
"publint": "^0.2.7",
Expand Down Expand Up @@ -172,7 +174,7 @@
"serve": "serve build -l 51000",
"test": "mocha --recursive --require test/fixtures.mjs",
"test:coverage": "c8 npm test",
"test:karma": "karma start tests/karma.conf.cjs -- --single-run --release",
"test:karma": "karma start tests/karma.conf.cjs -- --single-run",
"test:types": "tsc --pretty false build/playcanvas.d.ts"
}
}
26 changes: 12 additions & 14 deletions tests/framework/handlers/test_sprite_resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ describe("pc.SpriteHandler", function () {
this.app.assets.load(spriteAsset);

spriteAsset.ready(function (asset) {
ok(asset.resource.atlas);
expect(asset.resource.atlas).to.exist;

strictEqual(asset.loaded, true);
expect(asset.loaded).to.be.true;

strictEqual(asset.data.renderMode, 0);
strictEqual(asset.data.pixelsPerUnit, 100);
strictEqual(asset.data.textureAtlasAsset, atlasAsset.id);
strictEqual(asset.data.frameKeys[0], 0);
expect(asset.data.renderMode).to.equal(0);
expect(asset.data.pixelsPerUnit).to.equal(100);
expect(asset.data.textureAtlasAsset).to.equal(atlasAsset.id);
expect(asset.data.frameKeys[0]).to.equal(0);
done();
}, this);

Expand Down Expand Up @@ -70,17 +70,15 @@ describe("pc.SpriteHandler", function () {
this.app.assets.load(spriteAsset);

spriteAsset.ready(function (asset) {
expect(asset.resource.atlas).to.exist;

strictEqual(asset.loaded, true);
expect(asset.loaded).to.be.true;

ok(asset.resource.atlas);

strictEqual(asset.data.renderMode, 0);
strictEqual(asset.data.pixelsPerUnit, 100);
strictEqual(asset.data.textureAtlasAsset, atlasAsset.id);
strictEqual(asset.data.frameKeys[0], 0);
expect(asset.data.renderMode).to.equal(0);
expect(asset.data.pixelsPerUnit).to.equal(100);
expect(asset.data.textureAtlasAsset).to.equal(atlasAsset.id);
expect(asset.data.frameKeys[0]).to.equal(0);
done();

}, this);

spriteAsset.on('error', function (err) {
Expand Down
41 changes: 12 additions & 29 deletions tests/karma.conf.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
var fs = require('fs');
var path = require('path');

var release = process.argv.includes('--release');
var sourceFiles;

if (release) {
console.log('Testing release build');
sourceFiles = [path.resolve('build/playcanvas.js')];
} else {
console.log('Testing unbuilt sources');
sourceFiles = fs.readFileSync('build/dependencies.txt').toString().split('\n').map(function (value) {
return path.resolve(value.replace('../', ''));
});
}

module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -24,25 +8,18 @@ module.exports = function (config) {
},

// list of files / patterns to load in the browser
files: sourceFiles.concat([
// libraries
'node_modules/sinon/pkg/sinon.js',
'node_modules/chai/chai.js',

// test environment setup
'tests/setup.js',
files: [
'build/playcanvas.js',

// test files - change this to a specific file in order to run a single suite
'tests/**/test_*.js',

// resources - list any files here that need to be loaded by tests (i.e. via XHR), or
// need to be pre-loaded in order to provide helper functions etc.
{ pattern: 'tests/test-assets/**/*.*', included: false, served: true, watched: true, nocache: true },
{ pattern: 'tests/helpers/**/*.js', included: true, served: true, watched: true, nocache: true },
{ pattern: 'tests/framework/components/script/*.*', included: false, served: true, watched: true, nocache: true },
{ pattern: 'tests/platform/input/simulate_event.js', included: true, served: true, watched: true, nocache: true },
{ pattern: 'examples/assets/**/*.*', included: false, served: true, watched: true, nocache: true }
]),
],

// Serve .gz files with Content-Encoding: gzip
customHeaders: [{
Expand All @@ -60,7 +37,15 @@ module.exports = function (config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],
frameworks: ['mocha', 'chai', 'sinon'],

plugins: [
'karma-mocha',
'karma-chai',
'karma-sinon',
'karma-chrome-launcher',
'karma-spec-reporter'
],

// test results reporter to use
// possible values: 'dots', 'progress'
Expand All @@ -77,8 +62,6 @@ module.exports = function (config) {
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// browserConsoleLogOptions: config.LOG_WARN,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

Expand Down
33 changes: 0 additions & 33 deletions tests/setup.js

This file was deleted.