Skip to content

Commit

Permalink
chore: investigate so 77788717.
Browse files Browse the repository at this point in the history
  • Loading branch information
knightedcodemonkey committed Jan 24, 2024
1 parent 7e076d4 commit ec3c7c5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
4 changes: 4 additions & 0 deletions test/__fixtures__/paths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "0.0.0",
"type": "commonjs"
}
20 changes: 20 additions & 0 deletions test/__fixtures__/paths/src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

function getCurrentDirname(): string {
if (typeof __dirname === 'undefined') {
return dirname(fileURLToPath(import.meta.url))
}

return __dirname
}

function getCurrentFilepath(): string {
if (typeof __filename === 'undefined') {
return fileURLToPath(import.meta.url)
}

return __filename
}

export { getCurrentDirname, getCurrentFilepath }
10 changes: 10 additions & 0 deletions test/__fixtures__/paths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"declaration": true,
"strict": true,
"outDir": "dist"
},
"include": ["src"]
}
60 changes: 46 additions & 14 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const proDist = join(project, 'dist')
const paraDist = join(parallel, 'dist')
const esmDist = join(esmProject, 'dist')
const cjsDist = join(cjsProject, 'dist')
const paths = join(__dirname, '__fixtures__/paths')
const pathsDist = join(paths, 'dist')
const errDist = resolve(__dirname, '__fixtures__/compileErrors/dist')
const rmDist = async distPath => {
await rm(distPath, { recursive: true, force: true })
Expand All @@ -35,21 +37,51 @@ describe('duel', () => {
await rmDist(plainDist)
})

it('prints options help', async t => {
it('creates a dual ESM build from paths', async t => {
const spy = t.mock.method(global.console, 'log')

await duel(['--project', 'test/__fixtures__/paths', '--pkg-dir', paths])

// Third call because of logging for starting each build.
assert.ok(
spy.mock.calls[2].arguments[0].startsWith('Successfully created a dual ESM build'),
)
// Check that the expected files and extensions are there
assert.ok(existsSync(resolve(pathsDist, 'index.mjs')))
assert.ok(existsSync(resolve(pathsDist, 'index.d.mts')))
assert.ok(existsSync(resolve(pathsDist, 'esm/index.mjs')))
assert.ok(existsSync(resolve(pathsDist, 'esm/index.d.mts')))

// Check for runtime errors against Node.js
const { status: statusEsm } = spawnSync(
'node',
['test/__fixtures__/paths/dist/index.mjs'],
{ stdio: 'inherit' },
)
assert.equal(statusEsm, 0)
const { status: statusCjs } = spawnSync(
'node',
['test/__fixtures__/paths/dist/esm/index.mjs'],
{ stdio: 'inherit' },
)
assert.equal(statusCjs, 0)
})

it.skip('prints options help', async t => {
const spy = t.mock.method(global.console, 'log')

await duel(['--help'])
assert.ok(spy.mock.calls[1].arguments[0].startsWith('Options:'))
})

it('reports errors when passing invalid options', async t => {
it.skip('reports errors when passing invalid options', async t => {
const spy = t.mock.method(global.console, 'log')

await duel(['--invalid'])
assert.equal(spy.mock.calls[0].arguments[1], "Unknown option '--invalid'")
})

it('uses default --project value of "tsconfig.json"', async t => {
it.skip('uses default --project value of "tsconfig.json"', async t => {
const spy = t.mock.method(global.console, 'log')
const tsConfigPath = resolve('./tsconfig.json')
const tsConfigPathTemp = tsConfigPath.replace('tsconfig', 'tsconfig.temp')
Expand All @@ -60,21 +92,21 @@ describe('duel', () => {
await rename(tsConfigPathTemp, tsConfigPath)
})

it('reports errors when --project is a directory with no tsconfig.json', async t => {
it.skip('reports errors when --project is a directory with no tsconfig.json', async t => {
const spy = t.mock.method(global.console, 'log')

await duel(['-p', 'test/__fixtures__'])
assert.ok(spy.mock.calls[0].arguments[1].endsWith('no tsconfig.json.'))
})

it('reports errors when --project is not valid json', async t => {
it.skip('reports errors when --project is not valid json', async t => {
const spy = t.mock.method(global.console, 'log')

await duel(['-p', 'test/__fixtures__/esmProject/tsconfig.not.json'])
assert.ok(spy.mock.calls[0].arguments[1].endsWith('not parsable as JSONC.'))
})

it('reports errors when using deprecated --target-extension', async t => {
it.skip('reports errors when using deprecated --target-extension', async t => {
const spy = t.mock.method(global.console, 'log')

await duel(['-x', '.mjs'])
Expand All @@ -83,7 +115,7 @@ describe('duel', () => {
)
})

it('creates a dual CJS build', async t => {
it.skip('creates a dual CJS build', async t => {
const spy = t.mock.method(global.console, 'log')

t.after(async () => {
Expand Down Expand Up @@ -127,7 +159,7 @@ describe('duel', () => {
assert.equal(statusCjs, 0)
})

it('creates a dual ESM build', async t => {
it.skip('creates a dual ESM build', async t => {
const spy = t.mock.method(global.console, 'log')

t.after(async () => {
Expand Down Expand Up @@ -165,7 +197,7 @@ describe('duel', () => {
assert.equal(statusEsm, 0)
})

it('supports both builds output to directories', async t => {
it.skip('supports both builds output to directories', async t => {
const spy = t.mock.method(global.console, 'log')

t.after(async () => {
Expand All @@ -180,7 +212,7 @@ describe('duel', () => {
assert.ok(existsSync(resolve(proDist, 'cjs/index.cjs')))
})

it('supports import attributes and ts import assertion resolution mode', async t => {
it.skip('supports import attributes and ts import assertion resolution mode', async t => {
const spy = t.mock.method(global.console, 'log')

t.after(async () => {
Expand All @@ -193,7 +225,7 @@ describe('duel', () => {
)
})

it('supports running builds in parallel', async t => {
it.skip('supports running builds in parallel', async t => {
const spy = t.mock.method(global.console, 'log')

t.after(async () => {
Expand All @@ -208,13 +240,13 @@ describe('duel', () => {
assert.ok(existsSync(resolve(paraDist, 'cjs/index.cjs')))
})

it('works as a cli script', () => {
it.skip('works as a cli script', () => {
const resp = execSync('./src/duel.js -h', { cwd: resolve(__dirname, '..') })

assert.ok(resp.toString().indexOf('Options:') > -1)
})

it('reports compilation errors during a build', async t => {
it.skip('reports compilation errors during a build', async t => {
const spy = t.mock.method(global.console, 'log')
const spyExit = t.mock.method(process, 'exit')

Expand All @@ -235,7 +267,7 @@ describe('duel', () => {
assert.equal(spy.mock.calls[1].arguments[1], 'Compilation errors found.')
})

it('reports an error when no package.json file found', async t => {
it.skip('reports an error when no package.json file found', async t => {
const spy = t.mock.method(global.console, 'log')

t.after(async () => {
Expand Down

0 comments on commit ec3c7c5

Please sign in to comment.