GithubHelp home page GithubHelp logo

Comments (10)

Julien-R44 avatar Julien-R44 commented on June 14, 2024

I guess this is a problem related to your tsconfig. Probably moduleResolution : it should be set to at least Node16

Otherwise, please share your tsconfig.json

from runner.

malthe avatar malthe commented on June 14, 2024

This is my tsconfig.json:

{
    "compilerOptions": {
        "moduleResolution": "node16",
        "target": "es2022",
        "module": "node16",
        "lib": [
            "es2019",
            "esnext.asynciterable",
            "esnext.bigint"
        ],
        "strict": true,
        "sourceMap": true,
        "inlineSourceMap": false,
        "declaration": true,
        "allowSyntheticDefaultImports": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noImplicitAny": true,
        "noUnusedParameters": true,
        "noUnusedLocals": true,
        "declarationDir": "dist",
        "allowImportingTsExtensions": true,
        "noEmit": true,
        "outDir": "dist"
    },
    "include": [
        "src",
        "tests"
    ]
}

The error message:

~/co/ts-postgres$ npx tsc                                                                       2🚫
tests/hello.test.ts:8:28 - error TS2339: Property 'assert' does not exist on type 'TestContext'.

8 test('add two numbers', ({ assert }: TestContext) => {
                             ~~~~~~


Found 1 error in tests/hello.test.ts:8

from runner.

Julien-R44 avatar Julien-R44 commented on June 14, 2024

Thanks!
where is your test.ts file located? i'm talking about the file that contains this:

import { configure, processCLIArgs, run } from '@japa/runner'
import { assert } from '@japa/assert'
import { expect } from '@japa/expect'

processCLIArgs(process.argv.splice(2))
configure({
  files: ['tests/**/*.spec.ts'],
  plugins: [assert(), expect()],
})

run()

If you keep the default location, it should be in ./bin/test.ts. And if this is the case, you need to include it in your include tsconfig :

{
    "compilerOptions" : {
      // ....
    },
    "include" : [
        "bin", // Here 
        "src",
        "tests"
    ]
}

Otherwise, the module augmentation performed by importing @japa/assert will not be effective

from runner.

malthe avatar malthe commented on June 14, 2024

Adding "bin" (where my "test.ts" file resides) actually does not change anything. Nor does using "node16" as the module resolution setting.

from runner.

Julien-R44 avatar Julien-R44 commented on June 14, 2024

Did you tried restarting the typescript server / editor after updating that ? ( I am pretty sure this is the solution )

Otherwise, can you provide a reproduction repo please?

from runner.

malthe avatar malthe commented on June 14, 2024

@Julien-R44 see https://github.com/malthe/japa-runner/tree/typing-issue – thanks!

from runner.

Julien-R44 avatar Julien-R44 commented on June 14, 2024

It works just fine for me dude :
image
image

So yeah, i believe this was related to include.

from runner.

malthe avatar malthe commented on June 14, 2024

I set up a workflow to run via GitHub Actions on that same repo.

Here's a run that demonstrates the error: https://github.com/malthe/japa-runner/actions/runs/7293525876/job/19876751955.

from runner.

Julien-R44 avatar Julien-R44 commented on June 14, 2024

You need to remove the TestContext annotation on this line : https://github.com/malthe/japa-runner/blob/1261dd00584b4594c2ac911297df71ff67be57a1/tests/math.test.ts#L8

You don't need it. This should works :

test('add two numbers', ({ assert }) => {
  assert.equal(sum(2, 2), 4)
})

And, if ever you need it the augmented TestContext type, you should import it through @japa/runner/core not @japa/core

+ import type { TestContext } from '@japa/runner/core';
- import type { TestContext } from '@japa/core';

from runner.

malthe avatar malthe commented on June 14, 2024

Thanks – works beautifully 🎄

from runner.

Related Issues (20)

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.