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

deno test and deno test --no-check get different results due to declaration #10861

Closed
KyleJune opened this issue Jun 5, 2021 · 2 comments · Fixed by #13025
Closed

deno test and deno test --no-check get different results due to declaration #10861

KyleJune opened this issue Jun 5, 2021 · 2 comments · Fixed by #13025
Assignees
Labels
bug Something isn't working correctly needs investigation requires further investigation before determining if it is an issue or not

Comments

@KyleJune
Copy link
Contributor

KyleJune commented Jun 5, 2021

In the code sample below, the parent Example class sets thing to the first arg of the constructor. For the child class, the constructor knows that the super constructor sets thing to the first arg, so it doesn't assign it directly. If I try declaring the type for the thing property on the Example2 class, I get warnings for deno-ts 2564 and 2612. As shown in the screenshot below, one of the recommended fixes is "Prefix with 'declare'" and it resolves the issue.

image

If I try using the declared property, it doesn't show any warnings or errors.

image

import { assertEquals } from "https://deno.land/std@0.97.0/testing/asserts.ts";

interface Thing {
  x: number;
  y: number;
}

interface Thing2 extends Thing {
  z: number;
}

class Example {
  thing: Thing;

  constructor(thing: Thing) {
    this.thing = thing;
  }
}

Deno.test("example 1", () => {
  const example = new Example({x:2, y:3});
  const {x, y} = example.thing;
  assertEquals(x * y, 6);
})

class Example2 extends Example {
  declare thing: Thing2;
  
  constructor(thing: Thing2) {
    super(thing);
  }
}

Deno.test("example 2", () => {
  const example = new Example2({x:2, y:3, z:4});
  const {x, y, z} = example.thing;
  assertEquals(x * y * z, 24);
})

If I run the above deno tests, the results change after using --no-check. In the example below, the first 2 runs without --no-check are successful. As soon as I run with --no-check, the example 2 test case fails with an error saying "TypeError: Cannot destructure property 'x' of 'example.thing' as it is undefined.". The following 2 runs without --no-check now fail with the same error. The only way to get the error go away without --no-check is to edit the file, but if I run deno test with --no-check again, it ends up causing the issue to happen again. I believe the correct behavior would be for the tests to pass with or without the --no-check flag.

$ deno test example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
running 2 tests from file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
test example 1 ... ok (3ms)
test example 2 ... ok (1ms)

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (631ms)

$ deno test example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
running 2 tests from file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
test example 1 ... ok (1ms)
test example 2 ... ok (2ms)

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (625ms)

$ deno test --no-check example_test.ts
running 2 tests from file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
test example 1 ... ok (3ms)
test example 2 ... FAILED (1ms)

failures:

example 2
TypeError: Cannot destructure property 'x' of 'example.thing' as it is undefined.
    at file:///home/kyle/Projects/deno/oauth2_server/example_test.ts:36:10
    at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
    at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
    at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
    at runTest (deno:runtime/js/40_testing.js:199:13)
    at Object.runTests (deno:runtime/js/40_testing.js:244:13)
    at async file:///home/kyle/Projects/deno/oauth2_server/$deno$test.js:1:1

failures:

        example 2

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (41ms)

$ deno test example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
running 2 tests from file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
test example 1 ... ok (1ms)
test example 2 ... FAILED (2ms)

failures:

example 2
TypeError: Cannot destructure property 'x' of 'example.thing' as it is undefined.
    at file:///home/kyle/Projects/deno/oauth2_server/example_test.ts:36:10
    at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
    at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
    at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
    at runTest (deno:runtime/js/40_testing.js:199:13)
    at Object.runTests (deno:runtime/js/40_testing.js:244:13)
    at async file:///home/kyle/Projects/deno/oauth2_server/$deno$test.js:1:1

failures:

        example 2

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (617ms)
$ deno test example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
Check file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
running 2 tests from file:///home/kyle/Projects/deno/oauth2_server/example_test.ts
test example 1 ... ok (3ms)
test example 2 ... FAILED (1ms)

failures:

example 2
TypeError: Cannot destructure property 'x' of 'example.thing' as it is undefined.
    at file:///home/kyle/Projects/deno/oauth2_server/example_test.ts:36:10
    at asyncOpSanitizer (deno:runtime/js/40_testing.js:21:15)
    at resourceSanitizer (deno:runtime/js/40_testing.js:58:13)
    at exitSanitizer (deno:runtime/js/40_testing.js:85:15)
    at runTest (deno:runtime/js/40_testing.js:199:13)
    at Object.runTests (deno:runtime/js/40_testing.js:244:13)
    at async file:///home/kyle/Projects/deno/oauth2_server/$deno$test.js:1:1

failures:

        example 2

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (641ms)

I'm using the latest version of deno.

deno 1.10.3 (release, x86_64-unknown-linux-gnu)
v8 9.1.269.27
typescript 4.2.2
@kitsonk kitsonk self-assigned this Jun 6, 2021
@kitsonk kitsonk added the needs investigation requires further investigation before determining if it is an issue or not label Jun 6, 2021
@stale
Copy link

stale bot commented Aug 5, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 5, 2021
@kitsonk kitsonk removed the stale label Aug 5, 2021
@stale
Copy link

stale bot commented Oct 4, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly needs investigation requires further investigation before determining if it is an issue or not
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants