q5 2.9.22 → 2.9.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.vscode/launch.json +26 -0
  2. package/bun.lockb +0 -0
  3. package/p5-tests/js/chai_helpers.js +20 -0
  4. package/p5-tests/js/mocha_setup.js +2 -0
  5. package/p5-tests/js/modernizr.js +5 -0
  6. package/p5-tests/js/p5_helpers.js +135 -0
  7. package/p5-tests/js/sinon.js +5949 -0
  8. package/p5-tests/mocha.css +289 -0
  9. package/p5-tests/test.html +71 -0
  10. package/p5-tests/unit/color/color_conversion.js +68 -0
  11. package/p5-tests/unit/color/creating_reading.js +217 -0
  12. package/p5-tests/unit/color/p5.Color.js +1000 -0
  13. package/p5-tests/unit/color/setting.js +289 -0
  14. package/p5-tests/unit/core/2d_primitives.js +490 -0
  15. package/p5-tests/unit/core/attributes.js +115 -0
  16. package/p5-tests/unit/core/curves.js +139 -0
  17. package/p5-tests/unit/core/environment.js +248 -0
  18. package/p5-tests/unit/core/error_helpers.js +1158 -0
  19. package/p5-tests/unit/core/main.js +340 -0
  20. package/p5-tests/unit/core/p5.Element.js +773 -0
  21. package/p5-tests/unit/core/p5.Graphics.js +179 -0
  22. package/p5-tests/unit/core/preload.js +285 -0
  23. package/p5-tests/unit/core/rendering.js +116 -0
  24. package/p5-tests/unit/core/structure.js +293 -0
  25. package/p5-tests/unit/core/transform.js +144 -0
  26. package/p5-tests/unit/core/version.js +28 -0
  27. package/p5-tests/unit/core/vertex.js +137 -0
  28. package/p5-tests/unit/dom/dom.js +2146 -0
  29. package/p5-tests/unit/events/acceleration.js +213 -0
  30. package/p5-tests/unit/events/keyboard.js +179 -0
  31. package/p5-tests/unit/events/mouse.js +487 -0
  32. package/p5-tests/unit/events/touch.js +180 -0
  33. package/p5-tests/unit/image/downloading.js +379 -0
  34. package/p5-tests/unit/image/filters.js +92 -0
  35. package/p5-tests/unit/image/loading.js +413 -0
  36. package/p5-tests/unit/image/p5.Image.js +201 -0
  37. package/p5-tests/unit/image/pixels.js +234 -0
  38. package/p5-tests/unit/io/files.js +378 -0
  39. package/p5-tests/unit/io/loadBytes.js +149 -0
  40. package/p5-tests/unit/io/loadImage.js +123 -0
  41. package/p5-tests/unit/io/loadJSON.js +185 -0
  42. package/p5-tests/unit/io/loadModel.js +215 -0
  43. package/p5-tests/unit/io/loadShader.js +176 -0
  44. package/p5-tests/unit/io/loadStrings.js +140 -0
  45. package/p5-tests/unit/io/loadTable.js +183 -0
  46. package/p5-tests/unit/io/loadXML.js +127 -0
  47. package/p5-tests/unit/io/saveModel.js +113 -0
  48. package/p5-tests/unit/io/saveTable.js +142 -0
  49. package/p5-tests/unit/math/calculation.js +452 -0
  50. package/p5-tests/unit/math/noise.js +66 -0
  51. package/p5-tests/unit/math/p5.Vector.js +1886 -0
  52. package/p5-tests/unit/math/random.js +177 -0
  53. package/p5-tests/unit/math/trigonometry.js +144 -0
  54. package/p5-tests/unit/spec.js +50 -0
  55. package/p5-tests/unit/typography/attributes.js +120 -0
  56. package/p5-tests/unit/typography/loadFont.js +162 -0
  57. package/p5-tests/unit/typography/p5.Font.js +63 -0
  58. package/p5-tests/unit/utilities/conversion.js +329 -0
  59. package/p5-tests/unit/utilities/time_date.js +133 -0
  60. package/package.json +1 -1
  61. package/q5.d.ts +172 -55
  62. package/q5.js +55 -40
  63. package/q5.min.js +1 -1
  64. package/src/q5-2d-image.js +7 -3
  65. package/src/q5-core.js +6 -2
  66. package/src/q5-math.js +1 -0
  67. package/src/q5-webgpu-canvas.js +8 -7
  68. package/src/q5-webgpu-drawing.js +15 -12
  69. package/src/q5-webgpu-image.js +1 -1
  70. package/src/q5-webgpu-text.js +17 -15
@@ -0,0 +1,149 @@
1
+ suite('loadBytes', function() {
2
+ var invalidFile = '404file';
3
+ var validFile = 'unit/assets/nyan_cat.gif';
4
+
5
+ test('_friendlyFileLoadError is called', async function() {
6
+ const _friendlyFileLoadErrorStub = sinon.stub(p5, '_friendlyFileLoadError');
7
+ try {
8
+ await promisedSketch(function(sketch, resolve, reject) {
9
+ sketch.preload = function() {
10
+ sketch.loadBytes(invalidFile, reject, resolve);
11
+ };
12
+ });
13
+ expect(
14
+ _friendlyFileLoadErrorStub.calledOnce,
15
+ 'p5._friendlyFileLoadError was not called'
16
+ ).to.be.true;
17
+ } finally {
18
+ _friendlyFileLoadErrorStub.restore();
19
+ }
20
+ });
21
+
22
+ testSketchWithPromise('error prevents sketch continuing', function(
23
+ sketch,
24
+ resolve,
25
+ reject
26
+ ) {
27
+ sketch.preload = function() {
28
+ sketch.loadBytes(invalidFile);
29
+ setTimeout(resolve, 50);
30
+ };
31
+
32
+ sketch.setup = function() {
33
+ reject(new Error('Setup called'));
34
+ };
35
+
36
+ sketch.draw = function() {
37
+ reject(new Error('Draw called'));
38
+ };
39
+ });
40
+
41
+ testSketchWithPromise('error callback is called', function(
42
+ sketch,
43
+ resolve,
44
+ reject
45
+ ) {
46
+ sketch.preload = function() {
47
+ sketch.loadBytes(
48
+ invalidFile,
49
+ function() {
50
+ reject(new Error('Success callback executed.'));
51
+ },
52
+ function() {
53
+ // Wait a bit so that if both callbacks are executed we will get an error.
54
+ setTimeout(resolve, 50);
55
+ }
56
+ );
57
+ };
58
+ });
59
+
60
+ testSketchWithPromise('loading correctly triggers setup', function(
61
+ sketch,
62
+ resolve,
63
+ reject
64
+ ) {
65
+ sketch.preload = function() {
66
+ sketch.loadBytes(validFile);
67
+ };
68
+
69
+ sketch.setup = function() {
70
+ resolve();
71
+ };
72
+ });
73
+
74
+ testSketchWithPromise('success callback is called', function(
75
+ sketch,
76
+ resolve,
77
+ reject
78
+ ) {
79
+ var hasBeenCalled = false;
80
+ sketch.preload = function() {
81
+ sketch.loadBytes(
82
+ validFile,
83
+ function() {
84
+ hasBeenCalled = true;
85
+ },
86
+ function(err) {
87
+ reject(new Error('Error callback was entered: ' + err));
88
+ }
89
+ );
90
+ };
91
+
92
+ sketch.setup = function() {
93
+ if (!hasBeenCalled) {
94
+ reject(new Error('Setup called prior to success callback'));
95
+ } else {
96
+ setTimeout(resolve, 50);
97
+ }
98
+ };
99
+ });
100
+
101
+ test('returns the correct object', async function() {
102
+ const object = await promisedSketch(function(sketch, resolve, reject) {
103
+ var _object;
104
+ sketch.preload = function() {
105
+ _object = sketch.loadBytes(validFile, function() {}, reject);
106
+ };
107
+
108
+ sketch.setup = function() {
109
+ resolve(_object);
110
+ };
111
+ });
112
+ assert.isObject(object);
113
+ // Check data format
114
+ expect(object.bytes).to.satisfy(function(v) {
115
+ return Array.isArray(v) || v instanceof Uint8Array;
116
+ });
117
+ // Validate data
118
+ var str = 'GIF89a';
119
+ // convert the string to a byte array
120
+ var rgb = str.split('').map(function(e) {
121
+ return e.charCodeAt(0);
122
+ });
123
+ // this will convert a Uint8Aray to [], if necessary:
124
+ var loaded = Array.prototype.slice.call(object.bytes, 0, str.length);
125
+ assert.deepEqual(loaded, rgb);
126
+ });
127
+
128
+ test('passes an object to success callback for object JSON', async function() {
129
+ const object = await promisedSketch(function(sketch, resolve, reject) {
130
+ sketch.preload = function() {
131
+ sketch.loadBytes(validFile, resolve, reject);
132
+ };
133
+ });
134
+ assert.isObject(object);
135
+ // Check data format
136
+ expect(object.bytes).to.satisfy(function(v) {
137
+ return Array.isArray(v) || v instanceof Uint8Array;
138
+ });
139
+ // Validate data
140
+ var str = 'GIF89a';
141
+ // convert the string to a byte array
142
+ var rgb = str.split('').map(function(e) {
143
+ return e.charCodeAt(0);
144
+ });
145
+ // this will convert a Uint8Aray to [], if necessary:
146
+ var loaded = Array.prototype.slice.call(object.bytes, 0, str.length);
147
+ assert.deepEqual(loaded, rgb);
148
+ });
149
+ });
@@ -0,0 +1,123 @@
1
+ suite('loadImage', function() {
2
+ var invalidFile = '404file';
3
+ var validFile = 'unit/assets/nyan_cat.gif';
4
+
5
+ test('_friendlyFileLoadError is called', async function() {
6
+ const _friendlyFileLoadErrorStub = sinon.stub(p5, '_friendlyFileLoadError');
7
+ try {
8
+ await promisedSketch(function(sketch, resolve, reject) {
9
+ sketch.preload = function() {
10
+ sketch.loadImage(invalidFile, reject, resolve);
11
+ };
12
+ });
13
+ expect(
14
+ _friendlyFileLoadErrorStub.calledOnce,
15
+ 'p5._friendlyFileLoadError was not called'
16
+ ).to.be.true;
17
+ } finally {
18
+ _friendlyFileLoadErrorStub.restore();
19
+ }
20
+ });
21
+
22
+ testSketchWithPromise('error prevents sketch continuing', function(
23
+ sketch,
24
+ resolve,
25
+ reject
26
+ ) {
27
+ sketch.preload = function() {
28
+ sketch.loadImage(invalidFile);
29
+ setTimeout(resolve(), 50);
30
+ };
31
+
32
+ sketch.setup = function() {
33
+ reject(new Error('Setup called'));
34
+ };
35
+
36
+ sketch.draw = function() {
37
+ reject(new Error('Draw called'));
38
+ };
39
+ });
40
+
41
+ testSketchWithPromise('error callback is called', function(
42
+ sketch,
43
+ resolve,
44
+ reject
45
+ ) {
46
+ sketch.preload = function() {
47
+ sketch.loadImage(
48
+ invalidFile,
49
+ function() {
50
+ reject(new Error('Success callback executed.'));
51
+ },
52
+ function() {
53
+ // Wait a bit so that if both callbacks are executed we will get an error.
54
+ setTimeout(resolve, 50);
55
+ }
56
+ );
57
+ };
58
+ });
59
+
60
+ testSketchWithPromise('loading correctly triggers setup', function(
61
+ sketch,
62
+ resolve,
63
+ reject
64
+ ) {
65
+ sketch.preload = function() {
66
+ sketch.loadImage(validFile);
67
+ };
68
+
69
+ sketch.setup = function() {
70
+ resolve();
71
+ };
72
+ });
73
+
74
+ testSketchWithPromise('success callback is called', function(
75
+ sketch,
76
+ resolve,
77
+ reject
78
+ ) {
79
+ var hasBeenCalled = false;
80
+ sketch.preload = function() {
81
+ sketch.loadImage(
82
+ validFile,
83
+ function() {
84
+ hasBeenCalled = true;
85
+ },
86
+ function(err) {
87
+ reject(new Error('Error callback was entered: ' + err));
88
+ }
89
+ );
90
+ };
91
+
92
+ sketch.setup = function() {
93
+ if (!hasBeenCalled) {
94
+ reject(new Error('Setup called prior to success callback'));
95
+ } else {
96
+ setTimeout(resolve, 50);
97
+ }
98
+ };
99
+ });
100
+
101
+ test('returns an object with correct data', async function() {
102
+ const image = await promisedSketch(function(sketch, resolve, reject) {
103
+ var _image;
104
+ sketch.preload = function() {
105
+ _image = sketch.loadImage(validFile, function() {}, reject);
106
+ };
107
+
108
+ sketch.setup = function() {
109
+ resolve(_image);
110
+ };
111
+ });
112
+ assert.instanceOf(image, p5.Image);
113
+ });
114
+
115
+ test('passes an object with correct data to callback', async function() {
116
+ const image = await promisedSketch(function(sketch, resolve, reject) {
117
+ sketch.preload = function() {
118
+ sketch.loadImage(validFile, resolve, reject);
119
+ };
120
+ });
121
+ assert.instanceOf(image, p5.Image);
122
+ });
123
+ });
@@ -0,0 +1,185 @@
1
+ suite('loadJSON', function() {
2
+ var invalidFile = '404file';
3
+ var jsonArrayFile = 'unit/assets/array.json';
4
+ var jsonObjectFile = 'unit/assets/object.json';
5
+ var jsonpObjectFile = 'unit/assets/object.js';
6
+ var jsonpArrayFile = 'unit/assets/array.js';
7
+
8
+ test('_friendlyFileLoadError is called', async function() {
9
+ const _friendlyFileLoadErrorStub = sinon.stub(p5, '_friendlyFileLoadError');
10
+ try {
11
+ await promisedSketch(function(sketch, resolve, reject) {
12
+ sketch.preload = function() {
13
+ sketch.loadJSON(invalidFile, reject, resolve);
14
+ };
15
+ });
16
+ expect(
17
+ _friendlyFileLoadErrorStub.calledOnce,
18
+ 'p5._friendlyFileLoadError was not called'
19
+ ).to.be.true;
20
+ } finally {
21
+ _friendlyFileLoadErrorStub.restore();
22
+ }
23
+ });
24
+
25
+ testSketchWithPromise('error prevents sketch continuing', function(
26
+ sketch,
27
+ resolve,
28
+ reject
29
+ ) {
30
+ sketch.preload = function() {
31
+ sketch.loadJSON(invalidFile, reject, function() {
32
+ setTimeout(resolve, 50);
33
+ });
34
+ };
35
+
36
+ sketch.setup = function() {
37
+ reject(new Error('Entered setup'));
38
+ };
39
+
40
+ sketch.draw = function() {
41
+ reject(new Error('Entered draw'));
42
+ };
43
+ });
44
+
45
+ testSketchWithPromise('error callback is called', function(
46
+ sketch,
47
+ resolve,
48
+ reject
49
+ ) {
50
+ sketch.preload = function() {
51
+ sketch.loadJSON(
52
+ invalidFile,
53
+ function() {
54
+ reject(new Error('Success callback executed.'));
55
+ },
56
+ function() {
57
+ // Wait a bit so that if both callbacks are executed we will get an error.
58
+ setTimeout(resolve, 50);
59
+ }
60
+ );
61
+ };
62
+ });
63
+
64
+ testSketchWithPromise('loading correctly triggers setup', function(
65
+ sketch,
66
+ resolve,
67
+ reject
68
+ ) {
69
+ sketch.preload = function() {
70
+ sketch.loadJSON(jsonObjectFile);
71
+ };
72
+
73
+ sketch.setup = function() {
74
+ resolve();
75
+ };
76
+ });
77
+
78
+ testSketchWithPromise('success callback is called', function(
79
+ sketch,
80
+ resolve,
81
+ reject
82
+ ) {
83
+ var hasBeenCalled = false;
84
+ sketch.preload = function() {
85
+ sketch.loadJSON(
86
+ jsonObjectFile,
87
+ function() {
88
+ hasBeenCalled = true;
89
+ },
90
+ function(err) {
91
+ reject(new Error('Error callback was entered: ' + err));
92
+ }
93
+ );
94
+ };
95
+
96
+ sketch.setup = function() {
97
+ if (!hasBeenCalled) {
98
+ reject(new Error('Setup called prior to success callback'));
99
+ } else {
100
+ setTimeout(resolve, 50);
101
+ }
102
+ };
103
+ });
104
+
105
+ test('returns an object for object JSON.', async function() {
106
+ const json = await promisedSketch(function(sketch, resolve, reject) {
107
+ var json;
108
+ sketch.preload = function() {
109
+ json = sketch.loadJSON(jsonObjectFile, function() {}, reject);
110
+ };
111
+
112
+ sketch.setup = function() {
113
+ resolve(json);
114
+ };
115
+ });
116
+ assert.isObject(json);
117
+ });
118
+
119
+ test('passes an object to success callback for object JSON.', async function() {
120
+ const json = await promisedSketch(function(sketch, resolve, reject) {
121
+ sketch.preload = function() {
122
+ sketch.loadJSON(jsonObjectFile, resolve, reject);
123
+ };
124
+ });
125
+ assert.isObject(json);
126
+ });
127
+
128
+ // Does not work with the current loadJSON.
129
+ test('returns an array for array JSON.');
130
+ // test('returns an array for array JSON.', async function() {
131
+ // const json = await promisedSketch(function(sketch, resolve, reject) {
132
+ // var json;
133
+ // sketch.preload = function() {
134
+ // json = sketch.loadJSON(jsonArrayFile, function() {}, reject);
135
+ // };
136
+ //
137
+ // sketch.setup = function() {
138
+ // resolve(json);
139
+ // };
140
+ // });
141
+ // assert.isArray(json);
142
+ // assert.lengthOf(json, 3);
143
+ // });
144
+
145
+ test('passes an array to success callback for array JSON.', async function() {
146
+ const json = await promisedSketch(function(sketch, resolve, reject) {
147
+ sketch.preload = function() {
148
+ sketch.loadJSON(jsonArrayFile, resolve, reject);
149
+ };
150
+ });
151
+ assert.isArray(json);
152
+ assert.lengthOf(json, 3);
153
+ });
154
+
155
+ test('passes an object to success callback for object JSONP.', async function() {
156
+ const json = await promisedSketch(function(sketch, resolve, reject) {
157
+ sketch.preload = function() {
158
+ sketch.loadJSON(
159
+ jsonpObjectFile,
160
+ { jsonpCallbackFunction: 'jsonpCallbackFunction' },
161
+ 'jsonp',
162
+ resolve,
163
+ reject
164
+ );
165
+ };
166
+ });
167
+ assert.isObject(json);
168
+ });
169
+
170
+ test('passes an array to success callback for array JSONP.', async function() {
171
+ const json = await promisedSketch(function(sketch, resolve, reject) {
172
+ sketch.preload = function() {
173
+ sketch.loadJSON(
174
+ jsonpArrayFile,
175
+ { jsonpCallbackFunction: 'jsonpCallbackFunction' },
176
+ 'jsonp',
177
+ resolve,
178
+ reject
179
+ );
180
+ };
181
+ });
182
+ assert.isArray(json);
183
+ assert.lengthOf(json, 3);
184
+ });
185
+ });
@@ -0,0 +1,215 @@
1
+ suite('loadModel', function() {
2
+ var invalidFile = '404file';
3
+ var validFile = 'unit/assets/teapot.obj';
4
+ var validObjFileforMtl='unit/assets/octa-color.obj';
5
+ var validSTLfile = 'unit/assets/ascii.stl';
6
+ var inconsistentColorObjFile = 'unit/assets/eg1.obj';
7
+ var objMtlMissing = 'unit/assets/objMtlMissing.obj';
8
+ var validSTLfileWithoutExtension = 'unit/assets/ascii';
9
+
10
+ test('_friendlyFileLoadError is called', async function() {
11
+ const _friendlyFileLoadErrorStub = sinon.stub(p5, '_friendlyFileLoadError');
12
+ try {
13
+ await promisedSketch(function(sketch, resolve, reject) {
14
+ sketch.preload = function() {
15
+ sketch.loadModel(invalidFile, reject, resolve);
16
+ };
17
+ });
18
+ expect(
19
+ _friendlyFileLoadErrorStub.calledOnce,
20
+ 'p5._friendlyFileLoadError was not called'
21
+ ).to.be.true;
22
+ } finally {
23
+ _friendlyFileLoadErrorStub.restore();
24
+ }
25
+ });
26
+
27
+ testSketchWithPromise('error prevents sketch continuing', function(
28
+ sketch,
29
+ resolve,
30
+ reject
31
+ ) {
32
+ sketch.preload = function() {
33
+ sketch.loadModel(invalidFile);
34
+ setTimeout(resolve, 50);
35
+ };
36
+
37
+ sketch.setup = function() {
38
+ reject(new Error('Setup called'));
39
+ };
40
+
41
+ sketch.draw = function() {
42
+ reject(new Error('Draw called'));
43
+ };
44
+ });
45
+
46
+ testSketchWithPromise('error callback is called', function(
47
+ sketch,
48
+ resolve,
49
+ reject
50
+ ) {
51
+ sketch.preload = function() {
52
+ sketch.loadModel(
53
+ invalidFile,
54
+ function() {
55
+ reject(new Error('Success callback executed.'));
56
+ },
57
+ function() {
58
+ // Wait a bit so that if both callbacks are executed we will get an error.
59
+ setTimeout(resolve, 50);
60
+ }
61
+ );
62
+ };
63
+ });
64
+
65
+ testSketchWithPromise('loading correctly triggers setup', function(
66
+ sketch,
67
+ resolve,
68
+ reject
69
+ ) {
70
+ sketch.preload = function() {
71
+ sketch.loadModel(validFile);
72
+ };
73
+
74
+ sketch.setup = function() {
75
+ resolve();
76
+ };
77
+ });
78
+
79
+ testSketchWithPromise('success callback is called', function(
80
+ sketch,
81
+ done
82
+ ) {
83
+ var hasBeenCalled = false;
84
+ sketch.preload = function() {
85
+ sketch.loadModel(
86
+ validFile,
87
+ function() {
88
+ hasBeenCalled = true;
89
+ done();
90
+ },
91
+ function(err) {
92
+ done(new Error('Error callback was entered: ' + err));
93
+ }
94
+ );
95
+ };
96
+
97
+ sketch.setup = function() {
98
+ if (!hasBeenCalled) {
99
+ done(new Error('Setup called prior to success callback'));
100
+ }
101
+ };
102
+ });
103
+
104
+ test('loads OBJ file with associated MTL file correctly', async function(){
105
+ const model = await promisedSketch(function (sketch,resolve,reject){
106
+ sketch.preload=function(){
107
+ sketch.loadModel(validObjFileforMtl,resolve,reject);
108
+ };
109
+ });
110
+ const expectedColors=[
111
+ 0, 0, 0.5,
112
+ 0, 0, 0.5,
113
+ 0, 0, 0.5,
114
+ 0, 0, 0.942654,
115
+ 0, 0, 0.942654,
116
+ 0, 0, 0.942654,
117
+ 0, 0.815632, 1,
118
+ 0, 0.815632, 1,
119
+ 0, 0.815632, 1,
120
+ 0, 0.965177, 1,
121
+ 0, 0.965177, 1,
122
+ 0, 0.965177, 1,
123
+ 0.848654, 1, 0.151346,
124
+ 0.848654, 1, 0.151346,
125
+ 0.848654, 1, 0.151346,
126
+ 1, 0.888635, 0,
127
+ 1, 0.888635, 0,
128
+ 1, 0.888635, 0,
129
+ 1, 0.77791, 0,
130
+ 1, 0.77791, 0,
131
+ 1, 0.77791, 0,
132
+ 0.5, 0, 0,
133
+ 0.5, 0, 0,
134
+ 0.5, 0, 0
135
+ ];
136
+ assert.deepEqual(model.vertexColors,expectedColors);
137
+ });
138
+ test('inconsistent vertex coloring throws error', async function() {
139
+ // Attempt to load the model and catch the error
140
+ let errorCaught = null;
141
+ try {
142
+ await promisedSketch(function(sketch, resolve, reject) {
143
+ sketch.preload = function() {
144
+ sketch.loadModel(inconsistentColorObjFile, resolve, reject);
145
+ };
146
+ });
147
+ } catch (error) {
148
+ errorCaught = error;
149
+ }
150
+
151
+ // Assert that an error was caught and that it has the expected message
152
+ assert.instanceOf(errorCaught, Error, 'No error thrown for inconsistent vertex coloring');
153
+ assert.equal(errorCaught.message, 'Model coloring is inconsistent. Either all vertices should have colors or none should.', 'Unexpected error message for inconsistent vertex coloring');
154
+ });
155
+
156
+ test('missing MTL file shows OBJ model without vertexColors', async function() {
157
+ const model = await promisedSketch(function(sketch, resolve, reject) {
158
+ sketch.preload = function() {
159
+ sketch.loadModel(objMtlMissing, resolve, reject);
160
+ };
161
+ });
162
+ assert.instanceOf(model, p5.Geometry);
163
+ assert.equal(model.vertexColors.length, 0, 'Model should not have vertex colors');
164
+ });
165
+
166
+ test('returns an object with correct data', async function() {
167
+ const model = await promisedSketch(function(sketch, resolve, reject) {
168
+ var _model;
169
+ sketch.preload = function() {
170
+ _model = sketch.loadModel(validFile, function() {}, reject);
171
+ };
172
+
173
+ sketch.setup = function() {
174
+ resolve(_model);
175
+ };
176
+ });
177
+ assert.instanceOf(model, p5.Geometry);
178
+ });
179
+
180
+ test('passes an object with correct data to callback', async function() {
181
+ const model = await promisedSketch(function(sketch, resolve, reject) {
182
+ sketch.preload = function() {
183
+ sketch.loadModel(validFile, resolve, reject);
184
+ };
185
+ });
186
+ assert.instanceOf(model, p5.Geometry);
187
+ });
188
+
189
+ test('resolves STL file correctly', async function() {
190
+ const model = await promisedSketch(function(sketch, resolve, reject) {
191
+ sketch.preload = function() {
192
+ sketch.loadModel(validSTLfile, resolve, reject);
193
+ };
194
+ });
195
+ assert.instanceOf(model, p5.Geometry);
196
+ });
197
+
198
+ test('resolves STL file correctly with explicit extension', async function() {
199
+ const model = await promisedSketch(function(sketch, resolve, reject) {
200
+ sketch.preload = function() {
201
+ sketch.loadModel(validSTLfileWithoutExtension, resolve, reject, '.stl');
202
+ };
203
+ });
204
+ assert.instanceOf(model, p5.Geometry);
205
+ });
206
+
207
+ test('resolves STL file correctly with case insensitive extension', async function() {
208
+ const model = await promisedSketch(function(sketch, resolve, reject) {
209
+ sketch.preload = function() {
210
+ sketch.loadModel(validSTLfileWithoutExtension, resolve, reject, '.STL');
211
+ };
212
+ });
213
+ assert.instanceOf(model, p5.Geometry);
214
+ });
215
+ });