-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b430742
commit 3573ca8
Showing
15 changed files
with
115 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { join } from 'node:path'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { getDefaultExtension } from '../src/utils/extension'; | ||
|
||
describe('should get extension correctly', () => { | ||
it('autoExtension is false', () => { | ||
const options = { | ||
format: 'cjs', | ||
root: '/path/to/root', | ||
autoExtension: false, | ||
}; | ||
|
||
const result = getDefaultExtension(options); | ||
|
||
expect(result).toEqual({ | ||
jsExtension: '.js', | ||
dtsExtension: '.d.ts', | ||
}); | ||
}); | ||
|
||
it('package.json is broken', () => { | ||
const options = { | ||
format: 'cjs', | ||
root: '/path/to/root', | ||
autoExtension: true, | ||
}; | ||
|
||
const result = getDefaultExtension(options); | ||
|
||
expect(result).toEqual({ | ||
jsExtension: '.js', | ||
dtsExtension: '.d.ts', | ||
}); | ||
}); | ||
|
||
it('format is cjs and type is module in package.json', () => { | ||
const options = { | ||
format: 'cjs', | ||
root: join(__dirname, 'fixtures/extension/type-module'), | ||
autoExtension: true, | ||
}; | ||
|
||
const result = getDefaultExtension(options); | ||
|
||
expect(result).toEqual({ | ||
jsExtension: '.cjs', | ||
dtsExtension: '.d.cts', | ||
isModule: true, | ||
}); | ||
}); | ||
|
||
it('format is cjs and type is commonjs in package.json', () => { | ||
const options = { | ||
format: 'cjs', | ||
root: join(__dirname, 'fixtures/extension/type-commonjs'), | ||
autoExtension: true, | ||
}; | ||
|
||
const result = getDefaultExtension(options); | ||
|
||
expect(result).toEqual({ | ||
jsExtension: '.js', | ||
dtsExtension: '.d.ts', | ||
isModule: false, | ||
}); | ||
}); | ||
|
||
it('format is esm and type is commonjs in package.json', () => { | ||
const options = { | ||
format: 'esm', | ||
root: join(__dirname, 'fixtures/extension/type-commonjs'), | ||
autoExtension: true, | ||
}; | ||
|
||
const result = getDefaultExtension(options); | ||
|
||
expect(result).toEqual({ | ||
jsExtension: '.mjs', | ||
dtsExtension: '.d.mts', | ||
isModule: false, | ||
}); | ||
}); | ||
|
||
it('format is esm and type is module in package.json', () => { | ||
const options = { | ||
format: 'esm', | ||
root: join(__dirname, 'fixtures/extension/type-module'), | ||
autoExtension: true, | ||
}; | ||
|
||
const result = getDefaultExtension(options); | ||
|
||
expect(result).toEqual({ | ||
jsExtension: '.js', | ||
dtsExtension: '.d.ts', | ||
isModule: true, | ||
}); | ||
}); | ||
}); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...es/core/tests/config/cjs/rslib.config.cjs → ...ests/fixtures/config/cjs/rslib.config.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...es/core/tests/config/esm/rslib.config.mjs → ...ests/fixtures/config/esm/rslib.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
packages/core/tests/fixtures/extension/type-commonjs/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/core/tests/fixtures/extension/type-module/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |