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

Inconsistent Behavior When Preparing Ava Environment #49

Open
anilhelvaci opened this issue Dec 19, 2022 · 2 comments
Open

Inconsistent Behavior When Preparing Ava Environment #49

anilhelvaci opened this issue Dec 19, 2022 · 2 comments

Comments

@anilhelvaci
Copy link
Owner

anilhelvaci commented Dec 19, 2022

What is the best way to setup test environment with ses and ava?

Important !!! Don't forget to checkout bugfix/ava-ses-env branch

When I was trying to find an answer to this question I've come across two main ways to setup ava;

  1.  import '@agoric/zoe/tools/prepare-test-env.js';
     import test from 'ava';
  2.  import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
    • I also saw a prepare-test-env-ava.js at the notifier package which is similar to the one from zoe. I'll drop it's content anyway.

       // @ts-check
       import '@endo/init';
      
       import { wrapTest } from '@endo/ses-ava';
       import rawTest from 'ava';
      
       export const test = wrapTest(rawTest);

Environement

  • MacOs Monterey 12.6
  • agoric-sdk: fedf049435d7307311219fbab1b2b342ec6acce8
  • ava: 4.3.3
  • ses-ava: ^0.2.31
  • endo/init: ^0.5.47
  • node: 16.19
  • npm: 8.19
  • yarn: 1.22.19

Problem

I can only make my tests work following the first approach but I'm concerned that I might be missing somethings by not making the tests work with approach two and it's sub-approach.

In order to narrow down the problem I've prepared a small test with multiple ava environments. The actual code is here.

// @ts-check

// import { test } from '@agoric/notifier/test/prepare-test-env-ava.js';
// import { test } from './prepare-test-env-ava.js';

import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

test('ses-ava', async t => {
	const test = harden({
		hello: 'hello',
	});

	t.log(test);
	t.is('is', 'is');
});

This is the command I use to run the test;

cd dapp-pool-lending-protocol
npx ava -v contract/test/avaSesEnv/test-avaSesEnv.js -m ses-ava

Below are the results;

  1. When we fetch initiate test environment importing from import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; the console output;

    Uncaught exception in contract/test/avaSesEnv/test-avaSesEnv.js
    
    AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: The expression evaluated to a falsy value:
    
    assert(refs.runnerChain)
    
    at async Promise.all (index 0)
    
    SES_UNHANDLED_REJECTION: (AssertionError#1)
     ✖ contract/test/avaSesEnv/test-avaSesEnv.js exited with a non-zero exit code: 1
     ✖ Couldn’t find any matching tests
    
    
  2. When we fetch initiate test environment importing from import { test } from '@agoric/notifier/test/prepare-test-env-ava.js'; the console output;

    Uncaught exception in contract/test/avaSesEnv/test-avaSesEnv.js
    
    SES_UNHANDLED_REJECTION: (AssertionError#1)
    ✖ contract/test/avaSesEnv/test-avaSesEnv.js exited with a non-zero exit code: 1
    ✖ Couldn’t find any matching tests
    
  3. When I copy/paste the contents of prepare-test-env-ava.js to a file in the same directory and import it like this import { test } from './prepare-test-env-ava.js'; the console output is;

     Uncaught exception in contract/test/avaSesEnv/test-avaSesEnv.js
    
    ✖ contract/test/avaSesEnv/test-avaSesEnv.js exited with a non-zero exit code: 1
    ✖ Couldn’t find any matching tests
    
    
  4. And if I do an import like this;

    import '@agoric/zoe/tools/prepare-test-env.js';
    import test from 'ava';

    The console output;

    ✔ ses-ava
    ℹ {
       hello: 'hello',
     }
      ─
    

    Seems to be working.

It's seems very strange to me that I get different outputs every time I use different imports. What do you think? @dckc

anilhelvaci added a commit that referenced this issue Dec 19, 2022
@dckc
Copy link

dckc commented Dec 19, 2022

When I agoric init a new project, the contract/test/test-contract.js file starts with:

import { test } from './prepare-test-env-ava.js';

where ./prepare-test-env-ava.js contains:

/**
 * Like prepare-test-env but also sets up ses-ava and provides
 * the ses-ava `test` function to be used as if it is the ava
 * `test` function.
 */

import '@endo/init/pre-bundle-source.js';
import '@agoric/zoe/tools/prepare-test-env.js';
// eslint-disable-next-line import/no-unresolved -- https://github.com/avajs/ava/issues/2951
import rawTest from 'ava';

// XXX wrapTest not working https://github.com/endojs/endo/issues/1235
// import { wrapTest } from '@endo/ses-ava';

export const test = rawTest;

Try that?

anilhelvaci added a commit that referenced this issue Dec 20, 2022
@anilhelvaci
Copy link
Owner Author

So import { wrapTest } from '@endo/ses-ava'; is not mandatory? @dckc

I observed that wrapTest fails in my dapp but I'm able to run tests that use it. What could be causing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants