Giter Club home page Giter Club logo

doctest-js's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar izqalan avatar kiwicopple avatar mainshayne233 avatar soedirgo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

doctest-js's Issues

Build fails

Running npm run build has two issues:

[webpack-cli] Unknown argument: -p

And:

[webpack-cli] Compilation finished
assets by status 1.52 KiB [cached] 1 asset
./src/index.js 39 bytes [built] [code generated] [1 error]

ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/linus.thiel/development/linus/doctest-js/node_modules/babel-preset-es2015/lib/index.js
    at createDescriptor (/Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at /Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-chain.js:384:26)
    at /Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-chain.js:347:7
    at Generator.next (<anonymous>)
    at buildRootChain (/Users/linus.thiel/development/linus/doctest-js/node_modules/@babel/core/lib/config/config-chain.js:129:29)

Expected result:

Build succeeds and a new file is produced in dist/index.js.

Feature: Point test fails to a file's @example line where the error is

Thanks for the lovely package.

Pondering...
Understandably, Jest appears to only ever point its errors at the evalValue() function inside safe_eval.js.

Does Jest have a mechanism for specifying the file & line of code where the @example test came from?
It would be a bit nicer if the fail messages from Jest et al. pointed users to the source @example of the trouble.

Jest's expect.extend() might be part of the puzzle.

Currently all failed tests appear to lead here...

FAIL  src/helpers/index.test.js
 Test suite failed to run

   SyntaxError: Unexpected identifier

     11 |
     12 | describe('Doctests', () => {
   > 13 |   doctest('src/helpers/array.js', { testingFunction: testFn })
        |   ^
     14 | })

     at evalValue (node_modules/@supabase/doctest-js/dist/index.js:571:100047)
     at exports.default (node_modules/@supabase/doctest-js/dist/index.js:571:100487)
     at node_modules/@supabase/doctest-js/dist/index.js:124:31475
         at Array.forEach (<anonymous>)
     at t.default (node_modules/@supabase/doctest-js/dist/index.js:124:31433)
     at src/helpers/index.test.js:13:3
     at Object.<anonymous> (src/helpers/index.test.js:12:1)

Not working with Windows

I may be doing something stupid, but I'm getting this even on the README example using jest:

test("should ", () => {
  expect("x").toBe("x")
  doctest("src/sum.js") //?
})

results from Jest runner:

 TypeError: doctest is not a function

      3 | test("should ", () => {
      4 |   expect("x").toBe("x")
    > 5 |   doctest("src/sum.js") //?
        |   ^
      6 | })
      7 |

๐Ÿ™‹โ€โ™‚๏ธ Does this support promises

@example LoadWidget() //=> Promise.resolve(true)

returns

  โ— Doctests โ€บ doctest: LoadWidget()

    Expected value   {}
    Received:
      {}
    
    Message:
      expected {} to deeply equal {}

Am I doing something wrong or is this not supported??

Test passes when function returns any (incorrect) falsy value

Bug report

A tested function which incorrectly returns any falsy value (0, false, "", null, undefined, etc) is considered passing by @supabase/doctest-js.

Describe the bug

When a function under test returns a falsy value, even if the doctest @example specifies a particular, different, value, the test passes.

Example function:

/**
 * @example sum(1, 2)
 * //=> 3
 */
export const sum = (a, b) => {
  return null;
}

And the test

import doctest from "@supabase/doctest-js";

describe("Doctests", () => {
  // file paths are relative to root of directory
  doctest("src/sum.js");
});

This passes (at least, when run through mocha).

Expected result

The expected result would be that when a function under test returns anything other than the result specified in the @example, the test fails.

System information

OS: MacOS Big Sur, 11.6.1
Node version: v14.18.0
@supabase/doctest-js version: 0.1.0
mocha version: 9.1.3

Not working with objects

this seems to be failing:

/**
 * @param {object} obj 
 * @private
 * @returns {string}
 *
 * @example
 * objectToQueryString({ 
 *  param1: 'hello', 
 *  param2: 'world 
 * })
 * //=>
 * 'param1=hello&param2=world'
 */
export function objectToQueryString(obj) {
  return Object.keys(obj)
    .map(param => `${param}=${this.obj[param]}`)
    .join('&')
}

Prognosis?

Great that you're picking this up! Just curious about your experience with the code base so far...

`doctest is not a function`

Bug report

TypeError: doctest is not a function

Describe the bug

Following the README, I used this example:

// src/sum.js

/**
 * Returns the sum of 2 numbers
 *
 * @example sum(1, 2)
 * //=> 3
 */
export const sum = (a, b) => {
  return a + b;
};

and my test:

//test/tests.js

import doctest from "@supabase/doctest-js";

describe("Doctests", () => {
  // file paths are relative to root of directory
  doctest("src/sum.js");
});

I installed mocha globally and ran npm test (after adding {..., "scripts": { "test": "mocha" } ... } in my package.json)

ran npm test and got this:

ฮป npm test

> [email protected] test C:\Users\logan\Projects\misc
> mocha


TypeError: doctest is not a function
    at Suite.<anonymous> (file:///C:/Users/logan/Projects/misc/test/tests.js:5:3)
    at Object.create (C:\Users\logan\AppData\Local\nvs\node\12.20.1\x64\node_modules\mocha\lib\interfaces\common.js:148:19)
    at context.describe.context.context (C:\Users\logan\AppData\Local\nvs\node\12.20.1\x64\node_modules\mocha\lib\interfaces\bdd.js:42:27)
    at file:///C:/Users/logan/Projects/misc/test/tests.js:3:1
    at ModuleJob.run (internal/modules/esm/module_job.js:145:37)
    at async Loader.import (internal/modules/esm/loader.js:182:24)
    at async Object.exports.loadFilesAsync (C:\Users\logan\AppData\Local\nvs\node\12.20.1\x64\node_modules\mocha\lib\esm-utils.js:33:20)
    at async singleRun (C:\Users\logan\AppData\Local\nvs\node\12.20.1\x64\node_modules\mocha\lib\cli\run-helpers.js:125:3)
    at async Object.exports.handler (C:\Users\logan\AppData\Local\nvs\node\12.20.1\x64\node_modules\mocha\lib\cli\run.js:362:5)
npm ERR! Test failed.  See above for more details.

I saw that you're doing some Windows path work. Could the error be due to that?

System information

  • OS: Window s10
  • Version of supabase-js: "@supabase/doctest-js": "^0.1.0"
  • Version of Node.js: Node 12.x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.