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

fix: fixed tests for node #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mszmida
Copy link
Contributor

@mszmida mszmida commented May 8, 2024

This change fixes compatibility of tests with Node and Jest. Current Node LTS version is v20.13.0. On GitHub Actions we are using:

image

@mszmida mszmida force-pushed the tests-fix-for-node branch 6 times, most recently from 3386906 to a443bbe Compare May 8, 2024 18:52
@nobkd
Copy link
Collaborator

nobkd commented May 8, 2024

Would recommend something like

import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

fileURLToPath(dirname(import.meta.url))

ref: nuejs/create-nue@86034d2


You can copy relatively much from e.g. here: https://github.com/nuejs/nue/blob/master/packages/nuekit/test/nuekit.test.js


Maybe something like the following incomplete example:

import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { promises as fs } from 'node:fs'

import { createKit } from '../src/nuekit.js'


const __dirname = fileURLToPath(dirname(import.meta.url))

// temporary directory
const root = join(__dirname, 'page-router-test')
const dist = join(root, '.dist')
const distDev = join(dist, 'dev')

// setup and teardown
beforeAll(async () => {
  await fs.rm(dist, { recursive: true, force: true })

  const nue = await createKit({ root }) // maybe not working (path problems...), but needed if not tested from root of monorepo but for this module only(?)
  await nue.build()
})

// ...

function read(filePath) {
  return fs.readFile(join(distDev, filePath), 'utf-8')
}

There might still be jest not defined and/or wrong environment errors...

@nobkd
Copy link
Collaborator

nobkd commented May 8, 2024

Maybe avoid jest.restoreAllMocks() if feasible and instead of jest.spyOn just spyOn
and restore the mock at the end of the test manually mocked.mockRestore()?
Just some ideas.

EDIT: (absolute) paths might be a problem with jest/... not sure, why though

@mszmida
Copy link
Contributor Author

mszmida commented May 8, 2024

@nobkd Thank you for the review and hints! Currently the tests are failing because esbuild path resolution works differently on node:

export async function getBuilder(is_esbuild) {
  const actual_cwd = process.env.ACTUAL_CWD || process.cwd()
  try {
    return is_esbuild ? await import(resolve('esbuild', `file://${actual_cwd}/`)) : Bun
  } catch {
    throw 'Bundler not found. Please use Bun or install esbuild'
  }
}

I will take a look on that tomorrow.

@tipiirai
Copy link
Contributor

@mszmida looks like some checks were not succesful, so I'm hesitant to merge this

@nobkd
Copy link
Collaborator

nobkd commented May 15, 2024

Yes it's not running properly currently, because something (jest or...) handles path resolution differently, I think...


Hidden as off-topic

@tipiirai The tests currently don't run automatically when new contributors make a pull request. I don't know if there is a way to let them run automatically regardless, or not.
But it would be great, if you would let those tests run before merging next time. I would have allowed the run, but I don't seem to have enough permissions to do so, so you'll have to do that.. :)

@tipiirai

This comment was marked as off-topic.

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

Successfully merging this pull request may close these issues.

None yet

3 participants