Files
pnpm/modules-mounter/daemon/test/createFuseHandlers.test.ts
Zoltan Kochan 187049055f chore: upgrade @typescript/native-preview to 7.0.0-dev.20260421.2 (#11332)
* chore: upgrade @typescript/native-preview to 7.0.0-dev.20260421.2

- Add explicit `types: ["node"]` to the shared tsconfig because tsgo
  20260421 no longer auto-acquires `@types/*` from `node_modules`.
- Refactor test files to explicitly import jest globals (`describe`,
  `it`, `test`, `expect`, `beforeEach`, etc.) from `@jest/globals`
  instead of relying on `@types/jest` ambient declarations. Under the
  new tsgo build, `import { jest } from '@jest/globals'` shadows the
  ambient `jest` namespace, breaking `@types/jest`'s `declare var
  describe: jest.Describe;` globals.
- Add `@jest/globals` to each package's devDependencies where tests
  now import from it, and add `@types/node` to packages that need it
  but were relying on hoisted resolution.
- Replace `fail()` calls with `throw new Error(...)` since `fail` is
  no longer globally available.

* chore: fix remaining tsgo type-strictness errors

- Strip `as <PnpmType>` casts on objects passed to toMatchObject /
  toStrictEqual / toEqual; @jest/globals rejects the typed objects
  (which include AsymmetricMatchers) vs. the repo-specific type.
- Type `jest.fn<...>()` explicitly where the mock's signature matters
  for toHaveBeenCalledWith.
- Replace `beforeEach(() => X)` with `beforeEach(() => { X })` so the
  return value is void, as the stricter jest typing requires.
- Use `expect.objectContaining({...})` in one place where the full
  expected object triggered stricter type resolution.
- Cast `prompt.mock.calls` arg through `as unknown as Record<...>[]`
  for patch.test.ts's nested-array matchers.
- Fix off-by-one `<reference path>` in pnpm/test/getConfig.test.ts
  that only surfaced now.
- Move `@jest/globals` from devDependencies to dependencies in the
  two `__utils__` packages that import it from `src/`.
- Clean up unused imports from the @jest/globals migration.

* chore: address Copilot review on #11332

- Move misplaced `@jest/globals` imports to the top import block in
  checkEngine, run.ts, and workspace/root-finder tests where the
  script dropped them below executable code.
- Replace `try { await x(); throw new Error('should have thrown') } catch`
  in bins/linker, lockfile/fs, and resolving/local-resolver tests with
  `await expect(x()).rejects.toMatchObject({...})`. The old pattern
  swallowed an unrelated `throw` if the under-test call silently
  succeeded, which would fail on the catch-block assertion with a
  misleading message.
2026-04-21 22:50:40 +02:00

121 lines
4.2 KiB
TypeScript

import path from 'node:path'
import { beforeAll, describe, expect, it, jest } from '@jest/globals'
import { STORE_VERSION } from '@pnpm/constants'
jest.unstable_mockModule('fuse-native', () => ({ default: { ENOENT: -2 } }))
const { default: Fuse } = await import('fuse-native')
const { createFuseHandlers } = await import('../src/createFuseHandlers.js')
type FuseHandlers = Awaited<ReturnType<typeof createFuseHandlers>>
describe('FUSE handlers', () => {
let handlers: FuseHandlers
beforeAll(async () => {
const fixture = path.join(import.meta.dirname, '__fixtures__/simple')
handlers = await createFuseHandlers(fixture, path.join(fixture, 'store', STORE_VERSION))
})
it('readdir', () => {
handlers.readdir('/', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files!.sort()).toStrictEqual([
'.pnpm',
'@zkochan',
'is-positive',
].sort())
})
handlers.readdir('/.pnpm', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files!.sort()).toStrictEqual([
'@zkochan+git-config@0.1.0',
'ini@1.3.4',
'is-positive@1.0.0',
].sort())
})
handlers.readdir('/.pnpm/is-positive@1.0.0', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files).toStrictEqual(['node_modules'])
})
handlers.readdir('/.pnpm/is-positive@1.0.0/node_modules', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files).toStrictEqual(['is-positive'])
})
handlers.readdir('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files).toStrictEqual(['git-config'])
})
handlers.readdir('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files!.sort()).toStrictEqual([
'package.json',
'.npmignore',
'README.md',
'LICENSE',
'Gruntfile.js',
'.travis.yml',
'.jshintrc',
'test',
'index.js',
].sort())
})
handlers.readdir('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config/test', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files!.sort()).toStrictEqual([
'index.js',
'fixtures',
].sort())
})
handlers.readdir('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config/does-not-exist', (returnCode, _files) => {
expect(returnCode).toBe(Fuse.ENOENT)
})
handlers.readdir('/.pnpm/is-positive@1.0.0/node_modules/is-positive', (returnCode, files) => {
expect(returnCode).toBe(0)
expect(files!.sort()).toStrictEqual([
'package.json',
'index.js',
'license',
'readme.md',
].sort())
})
handlers.readdir('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@types', (returnCode) => {
expect(returnCode).toBe(Fuse.ENOENT)
})
})
it('getattr', () => {
handlers.getattr('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config/index.js', (returnCode, stat) => {
expect(returnCode).toBe(0)
expect(stat.mode).toBe(33206)
})
handlers.getattr('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config/test/fixtures', (returnCode, stat) => {
expect(returnCode).toBe(0)
expect(stat.mode).toBe(16877)
})
handlers.getattr('/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config/index.jsx', (returnCode, _stat) => {
expect(returnCode).toBe(Fuse.ENOENT)
})
handlers.getattr('/.pnpm/is-positive@1.0.0/node_modules/is-positive/package.json', (returnCode, stat) => {
expect(returnCode).toBe(0)
expect(stat.mode).toBe(33204)
})
})
it('open and read', (done) => {
const p = '/.pnpm/@zkochan+git-config@0.1.0/node_modules/@zkochan/git-config/index.js'
handlers.open(p, 0, (exitCode, fd) => {
expect(exitCode).toBe(0)
expect(fd && fd > 0).toBeTruthy()
const buffer = Buffer.alloc(10)
handlers.read(p, fd!, buffer, 10, 0, (readBytes) => {
expect(readBytes).toBe(10)
expect(buffer.toString()).toBe('var ini = ')
handlers.release(p, fd!, (exitCode) => {
expect(exitCode).toBe(0)
done()
})
})
})
})
})