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

test: autoExtension unit test #36

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/core/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { RslibConfig } from '../src/types/config';

describe('Should load config file correctly', () => {
test('Load config.js in cjs project', async () => {
const fixtureDir = join(__dirname, 'config/cjs');
const fixtureDir = join(__dirname, 'fixtures/config/cjs');
const configDir = join(fixtureDir, 'rslib.config.js');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -22,7 +22,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.mjs in cjs project', async () => {
const fixtureDir = join(__dirname, 'config/cjs');
const fixtureDir = join(__dirname, 'fixtures/config/cjs');
const configDir = join(fixtureDir, 'rslib.config.mjs');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -39,7 +39,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.ts in cjs project', async () => {
const fixtureDir = join(__dirname, 'config/cjs');
const fixtureDir = join(__dirname, 'fixtures/config/cjs');
const configDir = join(fixtureDir, 'rslib.config.ts');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -56,7 +56,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.cjs with defineConfig in cjs project', async () => {
const fixtureDir = join(__dirname, 'config/cjs');
const fixtureDir = join(__dirname, 'fixtures/config/cjs');
const configDir = join(fixtureDir, 'rslib.config.cjs');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -73,7 +73,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.js in esm project', async () => {
const fixtureDir = join(__dirname, 'config/esm');
const fixtureDir = join(__dirname, 'fixtures/config/esm');
const configDir = join(fixtureDir, 'rslib.config.js');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -90,7 +90,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.cjs in esm project', async () => {
const fixtureDir = join(__dirname, 'config/esm');
const fixtureDir = join(__dirname, 'fixtures/config/esm');
const configDir = join(fixtureDir, 'rslib.config.cjs');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -107,7 +107,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.ts in esm project', async () => {
const fixtureDir = join(__dirname, 'config/esm');
const fixtureDir = join(__dirname, 'fixtures/config/esm');
const configDir = join(fixtureDir, 'rslib.config.ts');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand All @@ -124,7 +124,7 @@ describe('Should load config file correctly', () => {
});

test('Load config.mjs with defineConfig in esm project', async () => {
const fixtureDir = join(__dirname, 'config/esm');
const fixtureDir = join(__dirname, 'fixtures/config/esm');
const configDir = join(fixtureDir, 'rslib.config.mjs');
const config = await loadConfig(configDir);
expect(config).toEqual({
Expand Down
7 changes: 0 additions & 7 deletions packages/core/tests/core.test.ts

This file was deleted.

99 changes: 99 additions & 0 deletions packages/core/tests/extension.test.ts
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,
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { defineConfig } = require('../../../../core/src/config');
const { defineConfig } = require('../../../../../core/src/config');

module.exports = defineConfig((args) => ({
lib: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from '../../../../core/src/config';
import { defineConfig } from '../../../../../core/src/config';

export default defineConfig((args) => ({
lib: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Loading