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

td.replace is breaking type definitions from sanctuary.js #327

Closed
hbarcelos opened this issue Jan 19, 2018 · 2 comments
Closed

td.replace is breaking type definitions from sanctuary.js #327

hbarcelos opened this issue Jan 19, 2018 · 2 comments

Comments

@hbarcelos
Copy link

hbarcelos commented Jan 19, 2018

I'm not sure, but maybe this might be related to #324.

I tried to reduce the example to the minimum possible to reproduce the issue, so it might not make sense.


Context

I'm using the following packages:

├── sanctuary@0.14.1
├── sanctuary-def@0.14.0
├── tape@4.8.0
└── testdouble@3.3.2

Also, I'm running node@8.9.4.

Code

Here are my files:

// sanctuary.js
const { create, env } = require('sanctuary')

module.exports = create({ checkTypes: true, env })
// utils/timer.js
exports.delay = function delay(timeMS) {
    return new Promise(resolve => {
        setTimeout(resolve, timeMS)
    })
}
// main.js
const { delay } = require('./utils/timer')
const S = require('./sanctuary')
module.exports = function main() {
    // empty body
}
// main.test.js
const test = require('tape')
const td = require('testdouble')

let timerStub
let main

test('setup', t => {
  timerStub = td.replace('../utils/timer')

  main = require('./')
  t.end()
})

test('actual test', t => {
  td.when(timerStub.delay(td.matchers.anything())).thenResolve()

  main()
  t.end()
})

test('teardown', t => {
  td.reset()
  t.end()
})

Current behavior

Run:

npx tape main.test.js

Result:

/home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary-def/index.js:2428
    if (either.isLeft) throw either.value();
                       ^

TypeError: Invalid value

def :: String -> StrMap (Array TypeClass) -> NonEmpty (Array Type) -> Function -> Function
                                                                      ^^^^^^^^
                                                                         1

1)  undefined :: Undefined

The value at position 1 is not a member of ‘Function’.

See https://github.com/sanctuary-js/sanctuary-def/tree/v0.14.0#Function for information about the Function type.

    at invalidValue (/home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary-def/index.js:2371:12)
    at Either.value (/home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary-def/index.js:1108:18)
    at assertRight (/home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary-def/index.js:2428:37)
    at /home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary-def/index.js:2468:26
    at /home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary-def/index.js:872:20
    at createSanctuary (/home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary/index.js:1239:3)
    at /home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary/index.js:4627:10
    at /home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary/index.js:198:22
    at Object.<anonymous> (/home/henrique/development/revmobads/late-install-scheduler/node_modules/sanctuary/index.js:212:2)
    at Module._compile (module.js:643:30)

If I remove the lines related to stubbing:

- timerStub = td.replace('../utils/timer')
# ...
- td.when(timerStub.delay(td.matchers.anything())).thenResolve()

Then the test executes as it should:

TAP version 13
# setup
# Report install correctly
# teardown

1..0
# tests 0
# pass  0

# ok

I'll see if I can help understand why exactly this is happening.

@searls
Copy link
Member

searls commented Jan 19, 2018

Can you please post the example as a repo that can be run with npm test?

@hbarcelos
Copy link
Author

Hi Justin, sorry for the delay here.
I'm closing this issue because I'm no longer able to reproduce it.

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