Skip to content
This repository was archived by the owner on Nov 2, 2025. It is now read-only.
This repository was archived by the owner on Nov 2, 2025. It is now read-only.

Snapshot files should be resolved relative from the file, not from cwd #48

@mcollina

Description

@mcollina

In a npm workspace project, I would like to:

  1. have the snapshots stored in the root of the module
  2. to run my tests from the root of the repository as well as the root of the module

I could not find a way to set it up. I thought to do it with snapshotFile but the snapshot entries are created with a packages/mymodule prefix added depending on my cwd(). I tracked it down to

libtap/lib/test.js

Lines 1199 to 1205 in 7d2934a

get fullname () {
const main = process.argv.slice(1).join(' ').trim()
return (this.parent ? this.parent.fullname
: main.indexOf(cwd) === 0 ? main.substr(cwd.length + 1)
: path.basename(main)).replace(/\\/g, '/') +
' ' + (this.name || '').trim()
}
.

The fullname of a test is created from cwd().

I'm currently fixing this with:

Object.defineProperty(t, 'fullname', {
  value: 'mymodule/mytest'
})

I can work on a PR but I would need some direction. I see two possible fixes:

  1. make the test.fullname not dependent from cwd()
  2. make the snapshot file not use the fullname for the internal entries

Wdyt?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions