diff --git a/package-lock.json b/package-lock.json index e48308cbf4..043ca3fb6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "libtess": "^1.2.2", "omggif": "^1.0.10", "pako": "^2.1.0", + "tl-util": "npm:@limzykenneth/tl-util@0.0.1", "zod": "^4.2.1" }, "devDependencies": { @@ -12805,6 +12806,13 @@ "node": ">=14.0.0" } }, + "node_modules/tl-util": { + "name": "@limzykenneth/tl-util", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@limzykenneth/tl-util/-/tl-util-0.0.1.tgz", + "integrity": "sha512-s7mR7HzSY7HUBzsVQWQzGm6GTGYOlJy/Y4WctTPtHepKIXYIB93mDrFggclEg/WqnWNP951shh2VAqDPZllGFw==", + "license": "MIT" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/package.json b/package.json index 4242f1be5a..4b195f6204 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "libtess": "^1.2.2", "omggif": "^1.0.10", "pako": "^2.1.0", - "zod": "^4.2.1" + "zod": "^4.2.1", + "tl-util": "npm:@limzykenneth/tl-util@0.0.1" }, "devDependencies": { "@eslint/compat": "^1.2.9", diff --git a/preview/index.html b/preview/index.html index 055f642f2e..6e74e1e38e 100644 --- a/preview/index.html +++ b/preview/index.html @@ -18,241 +18,18 @@ + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-bad-return/sketch.js b/test/manual-test-examples/fes/browser-bad-return/sketch.js new file mode 100644 index 0000000000..afd6eb6a57 --- /dev/null +++ b/test/manual-test-examples/fes/browser-bad-return/sketch.js @@ -0,0 +1,5 @@ +function setup() { + createCanvas(100, 100); +} + +return; diff --git a/test/manual-test-examples/fes/browser-invalid-token/index.html b/test/manual-test-examples/fes/browser-invalid-token/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-invalid-token/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-invalid-token/sketch.js b/test/manual-test-examples/fes/browser-invalid-token/sketch.js new file mode 100644 index 0000000000..5821a50094 --- /dev/null +++ b/test/manual-test-examples/fes/browser-invalid-token/sketch.js @@ -0,0 +1,5 @@ +let x = “not a string”; + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-missing-initializer/index.html b/test/manual-test-examples/fes/browser-missing-initializer/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-missing-initializer/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-missing-initializer/sketch.js b/test/manual-test-examples/fes/browser-missing-initializer/sketch.js new file mode 100644 index 0000000000..6c85fe6f90 --- /dev/null +++ b/test/manual-test-examples/fes/browser-missing-initializer/sketch.js @@ -0,0 +1,5 @@ +const a; + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-redeclare-variable/index.html b/test/manual-test-examples/fes/browser-redeclare-variable/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-redeclare-variable/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-redeclare-variable/sketch.js b/test/manual-test-examples/fes/browser-redeclare-variable/sketch.js new file mode 100644 index 0000000000..0c1d14da9e --- /dev/null +++ b/test/manual-test-examples/fes/browser-redeclare-variable/sketch.js @@ -0,0 +1,6 @@ +let a = 10; +let a = 100; + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-reference-cannot-access/index.html b/test/manual-test-examples/fes/browser-reference-cannot-access/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-reference-cannot-access/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-reference-cannot-access/sketch.js b/test/manual-test-examples/fes/browser-reference-cannot-access/sketch.js new file mode 100644 index 0000000000..7503a0e4c1 --- /dev/null +++ b/test/manual-test-examples/fes/browser-reference-cannot-access/sketch.js @@ -0,0 +1,6 @@ +console.log(a); +let a=100; + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-reference-not-defined/index.html b/test/manual-test-examples/fes/browser-reference-not-defined/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-reference-not-defined/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-reference-not-defined/sketch.js b/test/manual-test-examples/fes/browser-reference-not-defined/sketch.js new file mode 100644 index 0000000000..00b7a33cc7 --- /dev/null +++ b/test/manual-test-examples/fes/browser-reference-not-defined/sketch.js @@ -0,0 +1,5 @@ +console.log(x); + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-type-const-assign/index.html b/test/manual-test-examples/fes/browser-type-const-assign/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-const-assign/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-type-const-assign/sketch.js b/test/manual-test-examples/fes/browser-type-const-assign/sketch.js new file mode 100644 index 0000000000..d18d5dddc5 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-const-assign/sketch.js @@ -0,0 +1,6 @@ +const a = 100; +a=10; + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-type-not-function/index.html b/test/manual-test-examples/fes/browser-type-not-function/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-not-function/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-type-not-function/sketch.js b/test/manual-test-examples/fes/browser-type-not-function/sketch.js new file mode 100644 index 0000000000..d383086922 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-not-function/sketch.js @@ -0,0 +1,12 @@ +// Both cannot be tested at the same time because it throws a blocking error +let a = 100; +a(); + +// let b = { +// c: 10 +// }; +// b.c(); + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-type-null/index.html b/test/manual-test-examples/fes/browser-type-null/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-null/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-type-null/sketch.js b/test/manual-test-examples/fes/browser-type-null/sketch.js new file mode 100644 index 0000000000..34ea5afa49 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-null/sketch.js @@ -0,0 +1,6 @@ +let a = null; +console.log(a.property); + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-type-undefined/index.html b/test/manual-test-examples/fes/browser-type-undefined/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-undefined/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-type-undefined/sketch.js b/test/manual-test-examples/fes/browser-type-undefined/sketch.js new file mode 100644 index 0000000000..6a0d89131e --- /dev/null +++ b/test/manual-test-examples/fes/browser-type-undefined/sketch.js @@ -0,0 +1,6 @@ +let a; +console.log(a.property); + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/browser-unexpected-token/index.html b/test/manual-test-examples/fes/browser-unexpected-token/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/browser-unexpected-token/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/browser-unexpected-token/sketch.js b/test/manual-test-examples/fes/browser-unexpected-token/sketch.js new file mode 100644 index 0000000000..3e9c20b905 --- /dev/null +++ b/test/manual-test-examples/fes/browser-unexpected-token/sketch.js @@ -0,0 +1,5 @@ +function setup() { + createCanvas(100, 100); + + for (let i = 0; i < 5,; ++i){} +} diff --git a/test/manual-test-examples/fes/misspelled-close-match/index.html b/test/manual-test-examples/fes/misspelled-close-match/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/misspelled-close-match/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/misspelled-close-match/sketch.js b/test/manual-test-examples/fes/misspelled-close-match/sketch.js new file mode 100644 index 0000000000..ab361877fc --- /dev/null +++ b/test/manual-test-examples/fes/misspelled-close-match/sketch.js @@ -0,0 +1,4 @@ +function setup() { + createCanvas(100, 100); + vircle(10, 10, 10); +} diff --git a/test/manual-test-examples/fes/misspelled-multiple-match/index.html b/test/manual-test-examples/fes/misspelled-multiple-match/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/misspelled-multiple-match/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/misspelled-multiple-match/sketch.js b/test/manual-test-examples/fes/misspelled-multiple-match/sketch.js new file mode 100644 index 0000000000..eee129c10c --- /dev/null +++ b/test/manual-test-examples/fes/misspelled-multiple-match/sketch.js @@ -0,0 +1,4 @@ +function setup() { + createCanvas(100, 100); + pet(10); +} diff --git a/test/manual-test-examples/fes/misspelled-wrong-case/index.html b/test/manual-test-examples/fes/misspelled-wrong-case/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/misspelled-wrong-case/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/misspelled-wrong-case/sketch.js b/test/manual-test-examples/fes/misspelled-wrong-case/sketch.js new file mode 100644 index 0000000000..28ae8c56df --- /dev/null +++ b/test/manual-test-examples/fes/misspelled-wrong-case/sketch.js @@ -0,0 +1,4 @@ +function setup() { + createCanvas(100, 100); + Circle(10, 10, 10); +} diff --git a/test/manual-test-examples/fes/parameter-too-few/index.html b/test/manual-test-examples/fes/parameter-too-few/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/parameter-too-few/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/parameter-too-few/sketch.js b/test/manual-test-examples/fes/parameter-too-few/sketch.js new file mode 100644 index 0000000000..f46677f9e7 --- /dev/null +++ b/test/manual-test-examples/fes/parameter-too-few/sketch.js @@ -0,0 +1,4 @@ +function setup() { + createCanvas(100, 100); + circle(10, 10); +} diff --git a/test/manual-test-examples/fes/parameter-too-many/index.html b/test/manual-test-examples/fes/parameter-too-many/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/parameter-too-many/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/parameter-too-many/sketch.js b/test/manual-test-examples/fes/parameter-too-many/sketch.js new file mode 100644 index 0000000000..7473d00038 --- /dev/null +++ b/test/manual-test-examples/fes/parameter-too-many/sketch.js @@ -0,0 +1,4 @@ +function setup() { + createCanvas(100, 100); + circle(10, 10, 10, 10); +} diff --git a/test/manual-test-examples/fes/parameter-wrong-type-multiple/index.html b/test/manual-test-examples/fes/parameter-wrong-type-multiple/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/parameter-wrong-type-multiple/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/parameter-wrong-type-multiple/sketch.js b/test/manual-test-examples/fes/parameter-wrong-type-multiple/sketch.js new file mode 100644 index 0000000000..47d187b53b --- /dev/null +++ b/test/manual-test-examples/fes/parameter-wrong-type-multiple/sketch.js @@ -0,0 +1,4 @@ +function setup() { + createCanvas(100, 100); + image(false, 1, 2); +} diff --git a/test/manual-test-examples/fes/parameter-wrong-type/index.html b/test/manual-test-examples/fes/parameter-wrong-type/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/parameter-wrong-type/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/parameter-wrong-type/sketch.js b/test/manual-test-examples/fes/parameter-wrong-type/sketch.js new file mode 100644 index 0000000000..b9ba89e52a --- /dev/null +++ b/test/manual-test-examples/fes/parameter-wrong-type/sketch.js @@ -0,0 +1,5 @@ +function setup() { + createCanvas(100, 100); + background(false); + circle("invalid", 10, 10); +} diff --git a/test/manual-test-examples/fes/preload/index.html b/test/manual-test-examples/fes/preload/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/preload/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/preload/sketch.js b/test/manual-test-examples/fes/preload/sketch.js new file mode 100644 index 0000000000..dca5cf4d08 --- /dev/null +++ b/test/manual-test-examples/fes/preload/sketch.js @@ -0,0 +1,7 @@ +function preload() { + +} + +function setup() { + createCanvas(100, 100); +} diff --git a/test/manual-test-examples/fes/redeclare-p5-member/index.html b/test/manual-test-examples/fes/redeclare-p5-member/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/redeclare-p5-member/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/redeclare-p5-member/sketch.js b/test/manual-test-examples/fes/redeclare-p5-member/sketch.js new file mode 100644 index 0000000000..9a1df99f55 --- /dev/null +++ b/test/manual-test-examples/fes/redeclare-p5-member/sketch.js @@ -0,0 +1,6 @@ +let circle = 10; + +function setup() { + createCanvas(100, 100); + let fill = 'blue'; +} diff --git a/test/manual-test-examples/fes/top-level-p5-member/index.html b/test/manual-test-examples/fes/top-level-p5-member/index.html new file mode 100644 index 0000000000..df5c7bee23 --- /dev/null +++ b/test/manual-test-examples/fes/top-level-p5-member/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +
+

FES

+
+ + + + + \ No newline at end of file diff --git a/test/manual-test-examples/fes/top-level-p5-member/sketch.js b/test/manual-test-examples/fes/top-level-p5-member/sketch.js new file mode 100644 index 0000000000..2f64609ca3 --- /dev/null +++ b/test/manual-test-examples/fes/top-level-p5-member/sketch.js @@ -0,0 +1,5 @@ +circle(10, 10, 10); + +function setup() { + createCanvas(100, 100); +} diff --git a/test/unit/core/param_errors.js b/test/unit/core/param_errors.js index ca64f3c360..55cd19cf58 100644 --- a/test/unit/core/param_errors.js +++ b/test/unit/core/param_errors.js @@ -1,4 +1,4 @@ -import validateParams from '../../../src/core/friendly_errors/param_validator.js'; +import validateParams from '../../../src/friendly_errors/param_validator.js'; import * as constants from '../../../src/core/constants.js'; suite('Validate Params', function () { @@ -64,7 +64,7 @@ suite('Validate Params', function () { invalidInputs.forEach(({ input }) => { const result = mockP5Prototype._validate('p5.saturation', input); - assert.isTrue(result.error.startsWith('🌸 p5.js says: Expected Color or array or string at the first parameter, but received')); + assert.isTrue(result.error.toString().startsWith('Expected Color or array or string at the first parameter')); }); }); }); @@ -91,8 +91,8 @@ suite('Validate Params', function () { invalidInputs.forEach(({ name, input }) => { test(`blendMode(): ${name}`, () => { const result = mockP5Prototype._validate('p5.blendMode', [input]); - const expectedError = '🌸 p5.js says: Expected constant (please refer to documentation for allowed values) at the first parameter, but received ' + input + ' in p5.blendMode().'; - assert.equal(result.error, expectedError); + const expectedError = 'Expected constant (please refer to documentation for allowed values) at the first parameter, but received ' + input + ' in p5.blendMode().'; + assert.equal(result.error.toString(), expectedError); }); }); }); @@ -110,17 +110,17 @@ suite('Validate Params', function () { }); const invalidInputs = [ - { name: 'missing required arc parameters #4, #5', input: [200, 100, 100, 80], msg: '🌸 p5.js says: Expected at least 6 arguments, but received fewer in p5.arc(). For more information, see https://p5js.org/reference/p5/arc.' }, - { name: 'missing required param #0', input: [undefined, 100, 100, 80, 0, Math.PI, constants.PIE, 30], msg: '🌸 p5.js says: Expected number at the first parameter, but received undefined in p5.arc().' }, - { name: 'missing required param #4', input: [200, 100, 100, 80, undefined, 0], msg: '🌸 p5.js says: Expected number at the fifth parameter, but received undefined in p5.arc().' }, - { name: 'missing optional param #5', input: [200, 100, 100, 80, 0, undefined, Math.PI], msg: '🌸 p5.js says: Expected number at the sixth parameter, but received undefined in p5.arc().' }, - { name: 'wrong param type at #0', input: ['a', 100, 100, 80, 0, Math.PI, constants.PIE, 30], msg: '🌸 p5.js says: Expected number at the first parameter, but received string in p5.arc().' } + { name: 'missing required arc parameters #4, #5', input: [200, 100, 100, 80], msg: 'Expected at least 6 arguments, but received fewer in p5.arc(). For more information, see https://p5js.org/reference/p5/arc.' }, + { name: 'missing required param #0', input: [undefined, 100, 100, 80, 0, Math.PI, constants.PIE, 30], msg: 'Expected number at the first parameter, but received undefined in p5.arc().' }, + { name: 'missing required param #4', input: [200, 100, 100, 80, undefined, 0], msg: 'Expected number at the fifth parameter, but received undefined in p5.arc().' }, + { name: 'missing optional param #5', input: [200, 100, 100, 80, 0, undefined, Math.PI], msg: 'Expected number at the sixth parameter, but received undefined in p5.arc().' }, + { name: 'wrong param type at #0', input: ['a', 100, 100, 80, 0, Math.PI, constants.PIE, 30], msg: 'Expected number at the first parameter, but received string in p5.arc().' } ]; invalidInputs.forEach(({ name, input, msg }) => { test(`arc(): ${name}`, () => { const result = mockP5Prototype._validate('p5.arc', input); - assert.equal(result.error, msg); + assert.equal(result.error.toString(), msg); }); }); }); @@ -128,10 +128,9 @@ suite('Validate Params', function () { suite('validateParams: promise where no promise is expected', function () { test('image(): promise for first argument', function () { const result = mockP5Prototype._validate('p5.image', [Promise.resolve(), 0, 0]); - console.log(result); assert.equal( - result.error, - '🌸 p5.js says: Did you mean to put `await` before a loading function? An unexpected Promise was found. Expected Image or Element or Texture or Framebuffer or FramebufferTexture or Renderer or Graphics at the first parameter in p5.image().' + result.error.toString(), + 'Did you mean to put `await` before a loading function? An unexpected Promise was found. Expected Image or Element or Texture or Framebuffer or FramebufferTexture or Renderer or Graphics at the first parameter in p5.image().' ); }); }); @@ -145,37 +144,37 @@ suite('Validate Params', function () { suite('validateParams: a few edge cases', function () { const invalidInputs = [ - { fn: 'color', name: 'wrong type for optional parameter', input: [0, 0, 0, 'A'], msg: '🌸 p5.js says: Expected number at the fourth parameter, but received string in p5.color().' }, - { fn: 'color', name: 'superfluous parameter', input: [[0, 0, 0], 0], msg: '🌸 p5.js says: Expected number at the first parameter, but received array in p5.color().' }, - { fn: 'color', name: 'wrong element types', input: [['A', 'B', 'C']], msg: '🌸 p5.js says: Expected number at the first parameter, but received array in p5.color().' }, - { fn: 'rect', name: 'null, non-trailing, optional parameter', input: [0, 0, 0, 0, null, 0, 0, 0], msg: '🌸 p5.js says: Expected number at the fifth parameter, but received null in p5.rect().' }, - { fn: 'color', name: 'too many args + wrong types too', input: ['A', 'A', 0, 0, 0, 0, 0, 0, 0, 0], msg: '🌸 p5.js says: Expected at most 4 arguments, but received more in p5.color(). For more information, see https://p5js.org/reference/p5/color.' }, - { fn: 'line', name: 'null string given', input: [1, 2, 4, 'null'], msg: '🌸 p5.js says: Expected number at the fourth parameter, but received string in p5.line().' }, - { fn: 'line', name: 'NaN value given', input: [1, 2, 4, NaN], msg: '🌸 p5.js says: Expected number at the fourth parameter, but received NaN in p5.line().' } + { fn: 'color', name: 'wrong type for optional parameter', input: [0, 0, 0, 'A'], msg: 'Expected number at the fourth parameter, but received string in p5.color().' }, + { fn: 'color', name: 'superfluous parameter', input: [[0, 0, 0], 0], msg: 'Expected number at the first parameter, but received array in p5.color().' }, + { fn: 'color', name: 'wrong element types', input: [['A', 'B', 'C']], msg: 'Expected number at the first parameter, but received array in p5.color().' }, + { fn: 'rect', name: 'null, non-trailing, optional parameter', input: [0, 0, 0, 0, null, 0, 0, 0], msg: 'Expected number at the fifth parameter, but received null in p5.rect().' }, + { fn: 'color', name: 'too many args + wrong types too', input: ['A', 'A', 0, 0, 0, 0, 0, 0, 0, 0], msg: 'Expected at most 4 arguments, but received more in p5.color(). For more information, see https://p5js.org/reference/p5/color.' }, + { fn: 'line', name: 'null string given', input: [1, 2, 4, 'null'], msg: 'Expected number at the fourth parameter, but received string in p5.line().' }, + { fn: 'line', name: 'NaN value given', input: [1, 2, 4, NaN], msg: 'Expected number at the fourth parameter, but received NaN in p5.line().' } ]; invalidInputs.forEach(({ name, input, fn, msg }) => { test(`${fn}(): ${name}`, () => { const result = mockP5Prototype._validate(`p5.${fn}`, input); - assert.equal(result.error, msg); + assert.equal(result.error.toString(), msg); }); }); }); suite('validateParams: trailing undefined arguments', function () { const invalidInputs = [ - { fn: 'color', name: 'missing params #1, #2', input: [12, undefined, undefined], msg: '🌸 p5.js says: Expected number at the second parameter, but received undefined in p5.color().' }, + { fn: 'color', name: 'missing params #1, #2', input: [12, undefined, undefined], msg: 'Expected number at the second parameter, but received undefined in p5.color().' }, // Even though the undefined arguments are technically allowed for // optional parameters, it is more likely that the user wanted to call // the function with meaningful arguments. - { fn: 'random', name: 'missing params #0, #1', input: [undefined, undefined], msg: '🌸 p5.js says: All arguments for p5.random() are undefined. There is likely an error in the code.' }, - { fn: 'circle', name: 'missing compulsory parameter #2', input: [5, 5, undefined], msg: '🌸 p5.js says: Expected number at the third parameter, but received undefined in p5.circle().' } + { fn: 'random', name: 'missing params #0, #1', input: [undefined, undefined], msg: 'All arguments for p5.random() are undefined. There is likely an error in the code.' }, + { fn: 'circle', name: 'missing compulsory parameter #2', input: [5, 5, undefined], msg: 'Expected number at the third parameter, but received undefined in p5.circle().' } ]; invalidInputs.forEach(({ fn, name, input, msg }) => { test(`${fn}(): ${name}`, () => { const result = mockP5Prototype._validate(`p5.${fn}`, input); - assert.equal(result.error, msg); + assert.equal(result.error.toString(), msg); }); }); }); @@ -194,17 +193,17 @@ suite('Validate Params', function () { }); const invalidInputs = [ - { name: 'optional parameter, incorrect type', input: [65, 100, 100, 'a'], msg: '🌸 p5.js says: Expected number at the fourth parameter, but received string in p5.color().' }, - { name: 'extra parameter', input: [[65, 100, 100], 100], msg: '🌸 p5.js says: Expected number at the first parameter, but received array in p5.color().' }, - { name: 'incorrect element type', input: ['A', 'B', 'C'], msg: '🌸 p5.js says: Expected number at the first parameter, but received string in p5.color().' }, - { name: 'incorrect parameter count', input: ['A', 'A', 0, 0, 0, 0, 0, 0], msg: '🌸 p5.js says: Expected at most 4 arguments, but received more in p5.color(). For more information, see https://p5js.org/reference/p5/color.' } + { name: 'optional parameter, incorrect type', input: [65, 100, 100, 'a'], msg: 'Expected number at the fourth parameter, but received string in p5.color().' }, + { name: 'extra parameter', input: [[65, 100, 100], 100], msg: 'Expected number at the first parameter, but received array in p5.color().' }, + { name: 'incorrect element type', input: ['A', 'B', 'C'], msg: 'Expected number at the first parameter, but received string in p5.color().' }, + { name: 'incorrect parameter count', input: ['A', 'A', 0, 0, 0, 0, 0, 0], msg: 'Expected at most 4 arguments, but received more in p5.color(). For more information, see https://p5js.org/reference/p5/color.' } ]; invalidInputs.forEach(({ name, input, msg }) => { test(`color(): ${name}`, () => { const result = mockP5Prototype._validate('p5.color', input); - assert.equal(result.error, msg); + assert.equal(result.error.toString(), msg); }); }); }); @@ -224,7 +223,7 @@ suite('Validate Params', function () { test('set() with Boolean (invalid)', function () { const result = mockP5Prototype._validate('p5.set', [0, 0, true]); - assert.equal(result.error, '🌸 p5.js says: Expected number or array or object at the third parameter, but received boolean in p5.set().'); + assert.equal(result.error.toString(), 'Expected number or array or object at the third parameter, but received boolean in p5.set().'); }); }); diff --git a/test/unit/core/sketch_overrides.js b/test/unit/core/sketch_overrides.js index 1d3893372d..3504c00e32 100644 --- a/test/unit/core/sketch_overrides.js +++ b/test/unit/core/sketch_overrides.js @@ -1,6 +1,6 @@ import { verifierUtils -} from '../../../src/core/friendly_errors/sketch_verifier.js'; +} from '../../../src/friendly_errors/sketch_verifier.js'; suite('Sketch Verifier', function () { const mockP5 = { @@ -209,7 +209,7 @@ suite('Sketch Verifier', function () { test('Detects conflict with p5.js constant', function () { const userDefinitions = { - variables: [{ name: 'PI', line: 1 }], + variables: [{ name: 'PI', line: 0 }], functions: [] }; const result = verifierUtils.checkForConstsAndFuncs( @@ -220,7 +220,7 @@ suite('Sketch Verifier', function () { expect(result).toBe(true); expect(consoleSpy).toHaveBeenCalledWith( expect.stringContaining( - 'Constant "PI" on line 1 is being redeclared and conflicts with a p5.js constant' + 'constant "PI" on line 1 is being redeclared and conflicts with a p5.js constant' ) ); }); @@ -228,7 +228,7 @@ suite('Sketch Verifier', function () { test('Detects conflict with p5.js global function', function () { const userDefinitions = { variables: [], - functions: [{ name: 'rect', line: 2 }] + functions: [{ name: 'rect', line: 1 }] }; const result = verifierUtils.checkForConstsAndFuncs( userDefinitions, @@ -238,7 +238,7 @@ suite('Sketch Verifier', function () { expect(result).toBe(true); expect(consoleSpy).toHaveBeenCalledWith( expect.stringContaining( - 'Function "rect" on line 2 is being redeclared and conflicts with a p5.js function' + 'function "rect" on line 2 is being redeclared and conflicts with a p5.js function' ) ); });