Skip to content

Commit

Permalink
chore: refactor test file structure (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 authored Aug 9, 2024
1 parent 4e2fb8d commit 2216330
Show file tree
Hide file tree
Showing 74 changed files with 181 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { describe, expect, test } from 'vitest';

describe('autoExtension: true', () => {
test('generate .mjs in build artifacts with esm format when type is commonjs', async () => {
const fixturePath = join(__dirname, 'type-commonjs');
const fixturePath = join(__dirname, 'type-commonjs', 'default');
const { entryFiles } = await buildAndGetResults(fixturePath);
expect(extname(entryFiles.esm!)).toEqual('.mjs');
expect(extname(entryFiles.cjs!)).toEqual('.js');
});

test('generate .cjs in build artifacts with cjs format when type is module', async () => {
const fixturePath = join(__dirname, 'type-module');
const fixturePath = join(__dirname, 'type-module', 'default');
const { entryFiles } = await buildAndGetResults(fixturePath);
expect(extname(entryFiles.esm!)).toEqual('.js');
expect(extname(entryFiles.cjs!)).toEqual('.cjs');
Expand All @@ -20,21 +20,15 @@ describe('autoExtension: true', () => {

describe('autoExtension: false', () => {
test('generate .js in both cjs and esm build artifacts when type is commonjs', async () => {
const fixturePath = join(__dirname, 'type-commonjs');
const { entryFiles } = await buildAndGetResults(
fixturePath,
'autoExtension.false.config.ts',
);
const fixturePath = join(__dirname, 'type-commonjs', 'false');
const { entryFiles } = await buildAndGetResults(fixturePath);
expect(extname(entryFiles.esm!)).toEqual('.js');
expect(extname(entryFiles.cjs!)).toEqual('.js');
});

test('generate .js in both cjs and esm build artifacts when type is module', async () => {
const fixturePath = join(__dirname, 'type-module');
const { entryFiles } = await buildAndGetResults(
fixturePath,
'autoExtension.false.config.ts',
);
const fixturePath = join(__dirname, 'type-module', 'false');
const { entryFiles } = await buildAndGetResults(fixturePath);
expect(extname(entryFiles.esm!)).toEqual('.js');
expect(extname(entryFiles.cjs!)).toEqual('.js');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)],
source: {
entry: {
main: './src/index.ts',
main: '../../__fixtures__/src/index.ts',
},
},
});
5 changes: 5 additions & 0 deletions e2e/cases/auto-extension/type-commonjs/false/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "auto-extension-false-commonjs-test",
"version": "1.0.0",
"private": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
],
source: {
entry: {
main: './src/index.ts',
main: '../../__fixtures__/src/index.ts',
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)],
source: {
entry: {
main: './src/index.ts',
main: '../../__fixtures__/src/index.ts',
},
},
});
6 changes: 6 additions & 0 deletions e2e/cases/auto-extension/type-module/false/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "auto-extension-false-module-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
],
source: {
entry: {
main: './src/index.ts',
main: '../../__fixtures__/src/index.ts',
},
},
});
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/default/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@e2e/auto-external-default",
"name": "auto-external-default-test",
"dependencies": {
"react": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/default/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)],
source: {
entry: {
main: '../fixtures/src/index.ts',
main: '../__fixtures__/src/index.ts',
},
},
});
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/external-sub-path/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@e2e/auto-external-with-sub-path",
"name": "auto-external-with-sub-path-test",
"dependencies": {
"react": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/false/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@e2e/auto-external-false",
"name": "auto-external-false-test",
"dependencies": {
"react": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/false/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
],
source: {
entry: {
main: '../fixtures/src/index.ts',
main: '../__fixtures__/src/index.ts',
},
},
});
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/with-externals/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@e2e/auto-external-with-externals",
"name": "auto-external-with-externals-test",
"dependencies": {
"react": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/auto-external/with-externals/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
},
source: {
entry: {
main: '../fixtures/src/index.ts',
main: '../__fixtures__/src/index.ts',
},
},
});
1 change: 0 additions & 1 deletion e2e/cases/autoExtension/type-module/src/common.ts

This file was deleted.

3 changes: 0 additions & 3 deletions e2e/cases/autoExtension/type-module/src/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@src/*": ["./src/*"]
}
"rootDir": "src"
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
bundle: false,
dts: {
bundle: false,
abortOnError: false,
},
}),
generateBundleCjsConfig(__dirname, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"baseUrl": "./"
"baseUrl": "./",
"rootDir": "src"
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions e2e/cases/dts/bundle-false/auto-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-bundle-false-auto-extension-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default defineConfig({
],
source: {
entry: {
main: ['./src/**'],
main: ['../__fixtures__/src/**'],
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export default defineConfig({
bundle: false,
dts: {
bundle: false,
distPath: './dist/error',
abortOnError: false,
},
}),
generateBundleCjsConfig(__dirname, {
Expand All @@ -17,8 +15,8 @@ export default defineConfig({
],
source: {
entry: {
main: ['./src-error/**'],
main: ['../__fixtures__/src/**'],
},
tsconfigPath: 'tsconfig-error.json',
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default defineConfig({
],
source: {
entry: {
main: ['./src/**'],
main: ['../__fixtures__/src/**'],
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
],
source: {
entry: {
main: ['./src/**'],
main: ['../__fixtures__/src/**'],
},
},
});
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,7 +1,8 @@
{
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"baseUrl": "./"
"baseUrl": "./",
"rootDir": "src"
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions e2e/cases/dts/bundle/abort-on-error/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-bundle-abort-on-error-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
generateBundleEsmConfig(__dirname, {
dts: {
bundle: true,
abortOnError: false,
},
}),
generateBundleCjsConfig(__dirname),
Expand All @@ -14,5 +15,6 @@ export default defineConfig({
entry: {
main: './src/index.ts',
},
tsconfigPath: 'tsconfig.json',
},
});
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"baseUrl": "./",
"rootDir": "src-error"
"rootDir": "src"
},
"include": ["src-error"]
"include": ["src"]
}
6 changes: 6 additions & 0 deletions e2e/cases/dts/bundle/auto-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-bundle-auto-extension-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default defineConfig({
],
source: {
entry: {
main: './src/index.ts',
main: '../__fixtures__/src/index.ts',
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dts-bundle-false-test",
"name": "dts-bundle-basic-test",
"version": "1.0.0",
"private": true,
"type": "module"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default defineConfig({
],
source: {
entry: {
bundleName: './src/index.ts',
main: '../__fixtures__/src/index.ts',
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
6 changes: 6 additions & 0 deletions e2e/cases/dts/bundle/bundle-name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-bundle-bundle-name-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ export default defineConfig({
generateBundleEsmConfig(__dirname, {
dts: {
bundle: true,
distPath: './dist/error',
abortOnError: false,
},
}),
generateBundleCjsConfig(__dirname),
],
source: {
entry: {
main: './src-error/index.ts',
bundleName: '../__fixtures__/src/index.ts',
},
tsconfigPath: 'tsconfig-error.json',
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
6 changes: 6 additions & 0 deletions e2e/cases/dts/bundle/dist-path/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-bundle-dist-path-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default defineConfig({
],
source: {
entry: {
main: './src/index.ts',
main: '../__fixtures__/src/index.ts',
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dts-bundle-test",
"name": "dts-false-bundle-test",
"version": "1.0.0",
"private": true,
"type": "module"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default defineConfig({
],
source: {
entry: {
main: './src/index.ts',
main: '../__fixtures__/src/index.ts',
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
8 changes: 0 additions & 8 deletions e2e/cases/dts/bundle/tsconfig-error.json

This file was deleted.

Loading

0 comments on commit 2216330

Please sign in to comment.