#2923 ES Test Runner

SlimerDude Sun 14 Jul

Hi, this weekend I've been upgrading the Pickle library to utilise the new ES6 JavaScript syntax - and using the new / latest ES Test Runner has been integral.

For the most part, the following cmd works really well. (Thank you!)

fan nodeJs::Main test -keep afPickle

Except for one test that uses the dependant pod concurrent. The test makes use of this class.

@Serializable
@Js class Topic2644_Obj2 {
    static const AtomicInt instanceCount := AtomicInt()
	
    new make() {
        instanceCount.increment
    }
}

Which causes this error.

TEST FAILED
sys::Err: concurrent is not defined
ReferenceError: concurrent is not defined
    at Topic2644_Obj2.static$init (afPickle.js:2305:37)
    at Topic2644_Obj2.instanceCount (afPickle.js:2287:22)
    at Topic2644_Obj2.make$ (afPickle.js:2300:20)
    at Topic2644_Obj2.make (afPickle.js:2295:20)
    at file:///C:/Apps/fantom-1.0.80/temp/nodeJs/esm/afPickle.js:2210:31

Looking at the generated afPickle.js it does not look like the concurrent pod is imported.

// cjs require begin
import * as fan from './fan.js'
import * as sys from './sys.js'
// cjs require end

The generated ES class looks fine.

class Topic2644_Obj2 extends sys.Obj {
  constructor() {
    super();
    const this$ = this;
  }

  typeof() { return Topic2644_Obj2.type$; }

  static #instanceCount = undefined;

  static instanceCount() {
    if (Topic2644_Obj2.#instanceCount === undefined) {
      Topic2644_Obj2.static$init();
      if (Topic2644_Obj2.#instanceCount === undefined) Topic2644_Obj2.#instanceCount = null;
    }
    return Topic2644_Obj2.#instanceCount;
  }

  static make() {
    const $self = new Topic2644_Obj2();
    Topic2644_Obj2.make$($self);
    return $self;
  }

  static make$($self) {
    Topic2644_Obj2.instanceCount().increment();
    return;
  }

  static static$init() {
    Topic2644_Obj2.#instanceCount = concurrent.AtomicInt.make();
    return;
  }
}

So I guess my question is: are dependant imports currently missing from nodeJs::TestCmd?

matthew Mon 15 Jul

Hi Steve - I'm unable to reproduce this. I have a test pod that depends on concurrent and I created a simple class similar to the one you showed:

using concurrent

@Js class TopicTest : Test
{
  static const AtomicInt i := AtomicInt()
  new make() {
    i.increment
  }

  Void test() { verifyEq(i.val, 1) }
}

This code runs fine using the test tool. I may need to try and reproduce by building your actual afPickle pod. But are you running into this issue with a very simple test like the one above?

matthew Mon 15 Jul

FYI - i was able to build and run afPickle tests in ES mode using the tip of the Fantom repo:

$  fant -es afPickle                                                                   in pwsh at 11:58:59
-- Run: afPickle::SerializationTest.testLiterals
   Pass: afPickle::SerializationTest.testLiterals [200]
...
-- Run: afPickle::TestUsing.testUsingStr3
   Pass: afPickle::TestUsing.testUsingStr3 [1]
Time: 52ms
***
*** All tests passed! [7 types, 35 methods, 741 verifies]
***

SlimerDude Mon 15 Jul

Hi Matthew,

...
-- Run: afPickle::TestTopic2644.testSkipDefaults
   Pass: afPickle::TestTopic2644.testSkipDefaults [1]
-- Run: afPickle::TestTopic2644.testDefObjCreation
   Pass: afPickle::TestTopic2644.testDefObjCreation [1]
...

Thanks for testing Pickle for me - it's good to know all the tests pass! :D

But seriously, thanks for building Pickle from source and trying the tests.

I've created a simple pod, with just the simple TestTopic class - but still get the same result.

C:\> fan nodeJs::Main test -keep afPickle2
-- Run: afPickle2::TopicTest.test
TEST FAILED
sys::Err: concurrent is not defined
ReferenceError: concurrent is not defined
    at TopicTest.static$init (afPickle2.js:51:20)
    at TopicTest.i (afPickle2.js:27:17)
    at TopicTest.make$ (afPickle2.js:41:15)
    at make (afPickle2.js:35:15)
    at Method.invoke (sys.js:6129:17)
    at Type.make (sys.js:8524:21)
    at TestRunner.runMethod (util.js:2156:39)
    at file:///C:/Apps/fantom-1.0.80/temp/nodeJs/esm/util.js:2143:15
    at List.each (sys.js:4924:7)
    at TestRunner.runType (util.js:2141:20)

Time: 4ms
Failed:
  afPickle2::TopicTest.test
***
*** 1 FAILURES [1 types, 1 methods, 0 verifies]
***

EDIT: Upon investigating further, I switched the Fantom dist used for testing from tip to 1.0.80 (so it is the same as the dist used to build the pod) and it all works fine - concurrent is imported into the generated .js file.

There does seem to be some consistent incompatibility between the Fantom version that creates the pod, and the one used to run the test (I can re-create the error). But, to be honest, I don't think it warrants further investigation. If similar test errors crop up again, I'll just make sure the Fantom dists used to build and test are consistent.

Thank you Matthew for spending the time to look into this.

Login or Signup to reply.