Skip to content

Commit

Permalink
Added tests for gltfPipeline toDisk methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaStorm committed Jun 7, 2016
1 parent bc7693e commit 9cea1f8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
6 changes: 2 additions & 4 deletions lib/gltfPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ function processJSON(gltf, options, callback) {
throw err;
}
processJSONWithExtras(gltf, options, function(gltf) {
removePipelineExtras(gltf);
callback(gltf);
});
});
} else {
// If a resourcePath is not passed in, assume JSON is already embedded
processJSONWithExtras(gltf, options, function (gltf) {
removePipelineExtras(gltf);
processJSONWithExtras(gltf, options, function(gltf) {
callback(gltf);
});
}
Expand Down Expand Up @@ -103,7 +101,7 @@ function writeFile(gltf, outputPath, options, callback) {
}

function processJSONToDisk(gltf, outputPath, options, callback) {// isBinary, isEmbedded) {
processJSON(gltf, function(gltf) {
processJSON(gltf, options, function(gltf) {
writeFile(gltf, outputPath, options, callback);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/writeGltf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var fs = require('fs');
var fs = require('fs');
var path = require('path');
var Cesium = require('cesium');
var defined = Cesium.defined;
Expand Down
53 changes: 45 additions & 8 deletions specs/lib/gltfPipelineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var clone = require('clone');
var gltfPipeline = require('../../lib/gltfPipeline');
var processJSON = gltfPipeline.processJSON;
var processJSONWithExtras = gltfPipeline.processJSONWithExtras;
var processJSONToDisk = gltfPipeline.processJSONToDisk;
var processFile = gltfPipeline.processFile;
var processFileToDisk = gltfPipeline.processFileToDisk;
var readGltf = require('../../lib/readGltf');
Expand All @@ -14,7 +15,7 @@ var writeBinaryGltf = require('../../lib/writeBinaryGltf');

var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.gltf';
var glbPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.glb';
var outputPath = './output/test.gltf';
var outputPath = './output/';

describe('gltfPipeline', function() {
it('optimizes a gltf JSON given an embedded JSON', function() {
Expand Down Expand Up @@ -77,10 +78,10 @@ describe('gltfPipeline', function() {
var options = {};
readGltf(gltfPath, function(gltf) {
gltfCopy = gltf;
});
processFile(gltfPath, options, function(gltf) {
expect(gltf).toBeDefined();
expect(gltf).not.toBe(gltfCopy);
processFile(gltfPath, options, function (gltf) {
expect(gltf).toBeDefined();
expect(gltf).not.toBe(gltfCopy);
});
});
});

Expand All @@ -89,10 +90,46 @@ describe('gltfPipeline', function() {
var options = {};
readGltf(glbPath, function(gltf) {
gltfCopy = gltf;
processFile(glbPath, options, function (gltf) {
expect(gltf).toBeDefined();
expect(gltf).not.toBe(gltfCopy);
});
});
});

it('will write a file to the correct directory', function(done) {
var spy = spyOn(fs, 'writeFile').and.callFake(function(file, data, callback) {
callback();
});
var options = {};
processFileToDisk(gltfPath, outputPath, options, function() {
expect(spy).toHaveBeenCalled();
done();
});
processFile(glbPath, options, function(gltf) {
expect(gltf).toBeDefined();
expect(gltf).not.toBe(gltfCopy);
});

it('will write a file', function(done) {
var spy = spyOn(fs, 'writeFile').and.callFake(function(file, data, callback) {
callback();
});
var options = {};
processFileToDisk(gltfPath, outputPath, options, function() {
expect(spy).toHaveBeenCalled();
done();
});
});


it('will write a file from JSON', function(done) {
var spy = spyOn(fs, 'writeFile').and.callFake(function(file, data, callback) {
callback();
});
var options = {};
readGltf(gltfPath, function(gltf) {
processJSONToDisk(gltf, outputPath, options, function() {
expect(spy).toHaveBeenCalled();
done();
});
});
});
});

0 comments on commit 9cea1f8

Please sign in to comment.