Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Apr 26, 2024
1 parent 3ad3a1f commit eba7859
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 72 deletions.
7 changes: 6 additions & 1 deletion packages/cross-import/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/** @type {import('jest').Config} */
export default {
preset: '@techor/jest'
preset: '@techor/jest',
transformIgnorePatterns: [
'node_modules/(?!callsites)/',
/* should simulate real node runtime */
'fixtures/'
]
}
4 changes: 2 additions & 2 deletions packages/cross-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
"test": "pnpm build:main && node ./tests/real.mjs && jest",
"test": "jest",
"type-check": "tsc --noEmit",
"lint": "eslint src"
},
Expand Down Expand Up @@ -64,6 +64,6 @@
},
"devDependencies": {
"@master/css": "2.0.0-rc.24",
"pretty-bytes": "^6.1.0"
"nanoid": "^5.0.7"
}
}
1 change: 0 additions & 1 deletion packages/cross-import/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function crossImport(modulePath: string): any {
console.log('[cross-import] fall back to sucrase runtime transform:', modulePath)
}
return jiti(__filename, {
interopDefault: true,
cache: false,
debug: !!process.env.DEBUG,
onError(error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cross-import/tests/external.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import crossImport from '../src'

it('read module with third-party deps', () => {
expect(
crossImport(resolve(__dirname, 'external.ts')).default
crossImport(resolve(__dirname, 'fixtures/external.ts')).default
)
.toBeDefined()
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default } from 'pretty-bytes'
export { nanoid as default } from 'nanoid'
export * from './bar'
export const foo = 'foo'
File renamed without changes.
45 changes: 0 additions & 45 deletions packages/cross-import/tests/real.mjs

This file was deleted.

23 changes: 15 additions & 8 deletions packages/cross-import/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import crossImport from '../src'
import fs from 'fs'
import path from 'path'
import prettyBytes from 'pretty-bytes'
import { nanoid } from 'nanoid'
import { writeFileSync } from 'fs'

it('import .ts in .js', () => {
expect(
crossImport(path.resolve(__dirname, './foo.ts'))
crossImport(path.resolve(__dirname, 'fixtures/foo.ts'))
).toEqual({
'default': prettyBytes,
'default': nanoid,
'bar': 'bar',
'foo': 'foo'
})
})

it('read module from file', () => {
expect(
crossImport(path.resolve(__dirname, 'home-config.ts')))
crossImport(path.resolve(__dirname, 'fixtures/home-config.ts')))
.toEqual({
'default': {
'classes': { 'btn': 'font:12' },
Expand All @@ -28,7 +28,7 @@ it('read module from file', () => {

it('read module with export .css.ts', () => {
expect(
crossImport(path.resolve(__dirname, 'export.ts')))
crossImport(path.resolve(__dirname, 'fixtures/export.ts')))
.toEqual({
'default': {
'colors': {
Expand All @@ -40,9 +40,16 @@ it('read module with export .css.ts', () => {

it('read non-existent file', () => {
expect(() => {
crossImport(path.resolve(__dirname, 'idontexist.ts'))
crossImport(path.resolve(__dirname, 'fixtures/idontexist.ts'))
})
.toThrowError()
.toThrow()
})

it('read module with third-party deps', () => {
const configPath = path.join(__dirname, 'fixtures/config.tmp.js')
writeFileSync(configPath, 'module.exports = { a: 0 }')
const module1 = crossImport(configPath)
expect(module1).toEqual({ a: 0 })
})

// Do not test secondary imports in a test environment, inaccurate.
12 changes: 5 additions & 7 deletions packages/explore-config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/** @type {import('jest').Config} */
export default {
preset: '@techor/jest',
transform: {
'^.+\\.(t|j)sx?$': [
'@swc/jest'
],
},
transformIgnorePatterns: ['node_modules/(?!callsites)/'],
extensionsToTreatAsEsm: []
transformIgnorePatterns: [
'node_modules/(?!callsites)/',
/* should simulate real node runtime */
'fixtures/'
]
}
9 changes: 6 additions & 3 deletions packages/explore-config/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { dirname } from 'path'
import exploreConfig from '../src'

const __dirname = dirname(new URL(import.meta.url).pathname)

it('read .js config', () => {
const config = exploreConfig('../fixtures/master.css', { cwd: __dirname, extensions: ['js'] })
const config = exploreConfig('./fixtures/master.css', { cwd: __dirname, extensions: ['js'] })
expect(config).toEqual({
extends: [
{
Expand All @@ -15,7 +18,7 @@ it('read .js config', () => {
})

it('read .ts config', () => {
const config = exploreConfig('../fixtures/master.css', { cwd: __dirname, extensions: ['ts'] })
const config = exploreConfig('./fixtures/master.css', { cwd: __dirname, extensions: ['ts'] })
expect(config).toEqual({
extends: [
{
Expand All @@ -29,7 +32,7 @@ it('read .ts config', () => {
})

it('read .mjs config', () => {
const config = exploreConfig('../fixtures/master.css', { cwd: __dirname, extensions: ['mjs'] })
const config = exploreConfig('./fixtures/master.css', { cwd: __dirname, extensions: ['mjs'] })
expect(config).toEqual({
extends: [
{
Expand Down
13 changes: 10 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eba7859

Please sign in to comment.