Skip to content

Commit 63fe406

Browse files
committed
chore: update
1 parent 5937e58 commit 63fe406

File tree

2 files changed

+145
-123
lines changed

2 files changed

+145
-123
lines changed
Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from '@rstest/core';
1+
import { beforeAll, describe, expect, test } from '@rstest/core';
22
import { buildAndGetResults } from 'test-helper';
33

44
enum BannerFooter {
@@ -10,51 +10,67 @@ enum BannerFooter {
1010
DTS_FOOTER = '/*! hello footer dts */',
1111
}
1212

13-
test('banner and footer should work in js, css and dts', async () => {
14-
const fixturePath = __dirname;
15-
const { js, css, dts } = await buildAndGetResults({
16-
fixturePath,
17-
type: 'all',
18-
});
19-
20-
const jsContents = Object.values(js.contents);
21-
const cssContents = Object.values(css.contents);
22-
const dtsContents = Object.values(dts.contents);
13+
// There are 5 cases included in both tsc and tsgo
14+
// 1. bundle esm
15+
// 2. bundle cjs
16+
// 3. bundleless esm
17+
// 4. bundleless cjs
18+
// 5. bundle esm with minify enabled
19+
const checkBannerAndFooter = (
20+
contents: Record<string, string>[],
21+
type: 'js' | 'css' | 'dts',
22+
) => {
23+
for (const content of Object.values(contents)) {
24+
if (content) {
25+
const expectedBanner =
26+
type === 'js'
27+
? BannerFooter.JS_BANNER
28+
: type === 'css'
29+
? BannerFooter.CSS_BANNER
30+
: BannerFooter.DTS_BANNER;
31+
const expectedFooter =
32+
type === 'js'
33+
? BannerFooter.JS_FOOTER
34+
: type === 'css'
35+
? BannerFooter.CSS_FOOTER
36+
: BannerFooter.DTS_FOOTER;
2337

24-
// There are 5 cases included in both tsc and tsgo
25-
// 1. bundle esm
26-
// 2. bundle cjs
27-
// 3. bundleless esm
28-
// 4. bundleless cjs
29-
// 5. bundle esm with minify enabled
30-
const checkBannerAndFooter = (
31-
contents: Record<string, string>[],
32-
type: 'js' | 'css' | 'dts',
33-
) => {
34-
for (const content of Object.values(contents)) {
35-
if (content) {
36-
const expectedBanner =
37-
type === 'js'
38-
? BannerFooter.JS_BANNER
39-
: type === 'css'
40-
? BannerFooter.CSS_BANNER
41-
: BannerFooter.DTS_BANNER;
42-
const expectedFooter =
43-
type === 'js'
44-
? BannerFooter.JS_FOOTER
45-
: type === 'css'
46-
? BannerFooter.CSS_FOOTER
47-
: BannerFooter.DTS_FOOTER;
48-
49-
for (const value of Object.values(content)) {
50-
expect(value).toContain(expectedBanner);
51-
expect(value).toContain(expectedFooter);
52-
}
38+
for (const value of Object.values(content)) {
39+
expect(value).toContain(expectedBanner);
40+
expect(value).toContain(expectedFooter);
5341
}
5442
}
55-
};
43+
}
44+
};
45+
46+
describe('banner and footer should work in js, css and dts', () => {
47+
let jsContents: Record<string, string>[];
48+
let cssContents: Record<string, string>[];
49+
let dtsContents: Record<string, string>[];
50+
51+
beforeAll(async () => {
52+
const fixturePath = __dirname;
53+
const { js, css, dts } = await buildAndGetResults({
54+
fixturePath,
55+
type: 'all',
56+
});
57+
jsContents = Object.values(js.contents);
58+
cssContents = Object.values(css.contents);
59+
dtsContents = Object.values(dts.contents);
60+
});
61+
62+
test('tsc to generate declaration files', () => {
63+
checkBannerAndFooter(jsContents.slice(0, 5), 'js');
64+
checkBannerAndFooter(cssContents.slice(0, 5), 'css');
65+
checkBannerAndFooter(dtsContents.slice(0, 5), 'dts');
66+
});
5667

57-
checkBannerAndFooter(jsContents, 'js');
58-
checkBannerAndFooter(cssContents, 'css');
59-
checkBannerAndFooter(dtsContents, 'dts');
68+
test.skipIf(process.version.startsWith('v18'))(
69+
'tsgo to generate declaration files',
70+
() => {
71+
checkBannerAndFooter(jsContents.slice(-5), 'js');
72+
checkBannerAndFooter(cssContents.slice(-5), 'css');
73+
checkBannerAndFooter(dtsContents.slice(-5), 'dts');
74+
},
75+
);
6076
});

tests/integration/redirect/dtsTsgo.test.ts

Lines changed: 85 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
11
import path from 'node:path';
2-
import { beforeAll, expect, test } from '@rstest/core';
2+
import { beforeAll, describe, expect, test } from '@rstest/core';
33
import { buildAndGetResults } from 'test-helper';
44

5-
let contents: Awaited<ReturnType<typeof buildAndGetResults>>['contents'];
5+
describe.skipIf(process.version.startsWith('v18'))(
6+
'dts redirect with tsgo',
7+
() => {
8+
let contents: Awaited<ReturnType<typeof buildAndGetResults>>['contents'];
69

7-
beforeAll(async () => {
8-
const fixturePath = path.resolve(__dirname, './dts-tsgo');
9-
contents = (await buildAndGetResults({ fixturePath, type: 'dts' })).contents;
10-
}, 20000);
10+
beforeAll(async () => {
11+
const fixturePath = path.resolve(__dirname, './dts-tsgo');
12+
contents = (await buildAndGetResults({ fixturePath, type: 'dts' }))
13+
.contents;
14+
}, 20000);
1115

12-
test('redirect.dts.path: true with redirect.dts.extension: false - default', async () => {
13-
expect(contents.esm0).toMatchInlineSnapshot(`
14-
{
15-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/.hidden-folder/index.d.ts": "export declare const hiddenFolder = "This is a hidden folder";
16-
",
17-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/.hidden.d.ts": "export declare const hidden = "This is a hidden file";
18-
",
19-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/a.b/index.d.ts": "export declare const ab = "a.b";
20-
",
21-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/bar.baz.d.ts": "export declare const bar = "bar-baz";
22-
",
23-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/foo/foo.d.ts": "import { logRequest } from '../logger';
24-
import { logger } from '../../../../compile/prebundle-pkg';
25-
import { logRequest as logRequest2 } from '../logger';
26-
export { logRequest, logRequest2, logger };
27-
",
28-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/foo/index.d.ts": "export type Barrel = string;
29-
",
30-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/index.d.ts": "import { logRequest } from './logger';
31-
import { logger } from '../../../compile/prebundle-pkg';
32-
import type { Baz } from './';
33-
import type { LoggerOptions } from './types';
34-
import { defaultOptions } from './types.js';
35-
import sources = require('./logger');
36-
export { sources, type Baz as self, logRequest, logger, type LoggerOptions, defaultOptions, };
37-
export * from './foo';
38-
export * from './logger';
39-
export type { Foo } from './types';
40-
// export { Router } from 'express';
41-
export * from '../../../compile/prebundle-pkg';
42-
export type { Bar } from './types';
43-
export * from './.hidden';
44-
export * from './.hidden-folder';
45-
export * from './a.b';
46-
export * from './bar.baz';
47-
export * from './foo';
48-
export * from './types';
49-
",
50-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/logger.d.ts": "// import type { Request } from 'express';
51-
import type { LoggerOptions } from './types';
52-
export declare function logRequest(req: Request, options: LoggerOptions): void;
53-
",
54-
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/types.d.ts": "export interface LoggerOptions {
55-
logLevel: 'info' | 'debug' | 'warn' | 'error';
56-
logBody: boolean;
57-
}
58-
export declare const defaultOptions: LoggerOptions;
59-
export interface Foo {
60-
foo: string;
61-
}
62-
export interface Bar {
63-
bar: string;
64-
}
65-
export interface Baz {
66-
baz: string;
67-
}
68-
",
69-
}
70-
`);
71-
});
16+
test('redirect.dts.path: true with redirect.dts.extension: false - default', async () => {
17+
expect(contents.esm0).toMatchInlineSnapshot(`
18+
{
19+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/.hidden-folder/index.d.ts": "export declare const hiddenFolder = "This is a hidden folder";
20+
",
21+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/.hidden.d.ts": "export declare const hidden = "This is a hidden file";
22+
",
23+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/a.b/index.d.ts": "export declare const ab = "a.b";
24+
",
25+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/bar.baz.d.ts": "export declare const bar = "bar-baz";
26+
",
27+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/foo/foo.d.ts": "import { logRequest } from '../logger';
28+
import { logger } from '../../../../compile/prebundle-pkg';
29+
import { logRequest as logRequest2 } from '../logger';
30+
export { logRequest, logRequest2, logger };
31+
",
32+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/foo/index.d.ts": "export type Barrel = string;
33+
",
34+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/index.d.ts": "import { logRequest } from './logger';
35+
import { logger } from '../../../compile/prebundle-pkg';
36+
import type { Baz } from './';
37+
import type { LoggerOptions } from './types';
38+
import { defaultOptions } from './types.js';
39+
import sources = require('./logger');
40+
export { sources, type Baz as self, logRequest, logger, type LoggerOptions, defaultOptions, };
41+
export * from './foo';
42+
export * from './logger';
43+
export type { Foo } from './types';
44+
// export { Router } from 'express';
45+
export * from '../../../compile/prebundle-pkg';
46+
export type { Bar } from './types';
47+
export * from './.hidden';
48+
export * from './.hidden-folder';
49+
export * from './a.b';
50+
export * from './bar.baz';
51+
export * from './foo';
52+
export * from './types';
53+
",
54+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/logger.d.ts": "// import type { Request } from 'express';
55+
import type { LoggerOptions } from './types';
56+
export declare function logRequest(req: Request, options: LoggerOptions): void;
57+
",
58+
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/default/esm/types.d.ts": "export interface LoggerOptions {
59+
logLevel: 'info' | 'debug' | 'warn' | 'error';
60+
logBody: boolean;
61+
}
62+
export declare const defaultOptions: LoggerOptions;
63+
export interface Foo {
64+
foo: string;
65+
}
66+
export interface Bar {
67+
bar: string;
68+
}
69+
export interface Baz {
70+
baz: string;
71+
}
72+
",
73+
}
74+
`);
75+
});
7276

73-
test('redirect.dts.path: false with redirect.dts.extension: false', async () => {
74-
expect(contents.esm1).toMatchInlineSnapshot(`
77+
test('redirect.dts.path: false with redirect.dts.extension: false', async () => {
78+
expect(contents.esm1).toMatchInlineSnapshot(`
7579
{
7680
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/path-false/esm/.hidden-folder/index.d.ts": "export declare const hiddenFolder = "This is a hidden folder";
7781
",
@@ -129,10 +133,10 @@ test('redirect.dts.path: false with redirect.dts.extension: false', async () =>
129133
",
130134
}
131135
`);
132-
});
136+
});
133137

134-
test('redirect.dts.path: true with redirect.dts.extension: true', async () => {
135-
expect(contents.esm2).toMatchInlineSnapshot(`
138+
test('redirect.dts.path: true with redirect.dts.extension: true', async () => {
139+
expect(contents.esm2).toMatchInlineSnapshot(`
136140
{
137141
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/extension-true/esm/.hidden-folder/index.d.ts": "export declare const hiddenFolder = "This is a hidden folder";
138142
",
@@ -190,10 +194,10 @@ test('redirect.dts.path: true with redirect.dts.extension: true', async () => {
190194
",
191195
}
192196
`);
193-
});
197+
});
194198

195-
test('redirect.dts.path: false with dts.redirect.extension: true', async () => {
196-
expect(contents.esm3).toMatchInlineSnapshot(`
199+
test('redirect.dts.path: false with dts.redirect.extension: true', async () => {
200+
expect(contents.esm3).toMatchInlineSnapshot(`
197201
{
198202
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/path-false-extension-true/esm/.hidden-folder/index.d.ts": "export declare const hiddenFolder = "This is a hidden folder";
199203
",
@@ -251,10 +255,10 @@ test('redirect.dts.path: false with dts.redirect.extension: true', async () => {
251255
",
252256
}
253257
`);
254-
});
258+
});
255259

256-
test('redirect.dts.extension: true with dts.autoExtension: true', async () => {
257-
expect(contents.esm4).toMatchInlineSnapshot(`
260+
test('redirect.dts.extension: true with dts.autoExtension: true', async () => {
261+
expect(contents.esm4).toMatchInlineSnapshot(`
258262
{
259263
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/auto-extension-true/esm/.hidden-folder/index.d.mts": "export declare const hiddenFolder = "This is a hidden folder";
260264
",
@@ -312,7 +316,7 @@ test('redirect.dts.extension: true with dts.autoExtension: true', async () => {
312316
",
313317
}
314318
`);
315-
expect(contents.cjs).toMatchInlineSnapshot(`
319+
expect(contents.cjs).toMatchInlineSnapshot(`
316320
{
317321
"<ROOT>/tests/integration/redirect/dts-tsgo/dist/auto-extension-true/cjs/.hidden-folder/index.d.ts": "export declare const hiddenFolder = "This is a hidden folder";
318322
",
@@ -370,4 +374,6 @@ test('redirect.dts.extension: true with dts.autoExtension: true', async () => {
370374
",
371375
}
372376
`);
373-
});
377+
});
378+
},
379+
);

0 commit comments

Comments
 (0)