Skip to content

Commit c383f99

Browse files
committed
✅ add tests for i18n features
1 parent 7bdd782 commit c383f99

File tree

4 files changed

+124
-27
lines changed

4 files changed

+124
-27
lines changed

test/integration/i18n/fixtures.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { File, GlobalFixtures } from '../fixtures';
2+
3+
export class Fixtures extends GlobalFixtures {
4+
@File(__dirname, 'i18n.headers.txt')
5+
public static readonly i18nHeaders: string;
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ==UserScript==
2+
// @name i18n
3+
// @description this is a fantastic userscript
4+
// @description:en i18n description
5+
// @version 0.0.0
6+
// @match *://*/*
7+
// ==/UserScript==
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { HeadersProps, UserscriptPlugin } from 'webpack-userscript';
2+
3+
import { compile } from '../util';
4+
import { Volume } from '../volume';
5+
import { Fixtures } from './fixtures';
6+
7+
describe('i18n', () => {
8+
let input: Volume;
9+
10+
beforeEach(async () => {
11+
input = Volume.fromJSON({
12+
'/entry.js': Fixtures.entryJs,
13+
'/package.json': Fixtures.packageJson,
14+
});
15+
});
16+
17+
it('headers object', async () => {
18+
const output = await compile(input, {
19+
...Fixtures.webpackConfig,
20+
plugins: [
21+
new UserscriptPlugin({
22+
headers: {
23+
name: 'i18n',
24+
},
25+
i18n: {
26+
en: {
27+
description: 'i18n description',
28+
},
29+
},
30+
}),
31+
],
32+
});
33+
34+
expect(output.toJSON()).toEqual({
35+
'/dist/output.user.js': Fixtures.entryUserJs(Fixtures.i18nHeaders),
36+
'/dist/output.meta.js': Fixtures.i18nHeaders,
37+
});
38+
});
39+
40+
it('headers file', async () => {
41+
input.writeFileSync(
42+
'/headers.json',
43+
JSON.stringify({
44+
description: 'i18n description',
45+
}),
46+
);
47+
48+
const output = await compile(input, {
49+
...Fixtures.webpackConfig,
50+
plugins: [
51+
new UserscriptPlugin({
52+
headers: {
53+
name: 'i18n',
54+
},
55+
i18n: {
56+
en: '/headers.json',
57+
},
58+
}),
59+
],
60+
});
61+
62+
expect(output.toJSON()).toEqual({
63+
'/dist/output.user.js': Fixtures.entryUserJs(Fixtures.i18nHeaders),
64+
'/dist/output.meta.js': Fixtures.i18nHeaders,
65+
});
66+
});
67+
68+
it('headers provider', async () => {
69+
const output = await compile(input, {
70+
...Fixtures.webpackConfig,
71+
plugins: [
72+
new UserscriptPlugin({
73+
headers: {
74+
name: 'i18n',
75+
},
76+
i18n: {
77+
en: (headers): HeadersProps => ({
78+
...headers,
79+
description: 'i18n description',
80+
}),
81+
},
82+
}),
83+
],
84+
});
85+
86+
expect(output.toJSON()).toEqual({
87+
'/dist/output.user.js': Fixtures.entryUserJs(Fixtures.i18nHeaders),
88+
'/dist/output.meta.js': Fixtures.i18nHeaders,
89+
});
90+
});
91+
92+
it('unlocalizable tags', () => {
93+
const promise = compile(input, {
94+
...Fixtures.webpackConfig,
95+
plugins: [
96+
new UserscriptPlugin({
97+
headers: {
98+
name: 'i18n',
99+
},
100+
i18n: {
101+
en: {
102+
downloadURL: 'https://example.com',
103+
},
104+
},
105+
}),
106+
],
107+
});
108+
109+
return expect(promise).toReject();
110+
});
111+
});

test/integration/load-headers/index.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -202,31 +202,4 @@ describe('load-headers', () => {
202202
});
203203
});
204204
});
205-
206-
describe('i18n', () => {
207-
it('headers object', async () => {
208-
const output = await compile(input, {
209-
...Fixtures.webpackConfig,
210-
plugins: [
211-
new UserscriptPlugin({
212-
headers: {
213-
name: 'load-headers',
214-
},
215-
i18n: {
216-
en: {
217-
name: 'load-headers-en',
218-
},
219-
},
220-
}),
221-
],
222-
});
223-
224-
expect(output.toJSON()).toEqual({
225-
'/dist/output.user.js': Fixtures.entryUserJs(
226-
Fixtures.loadHeadersHeaders,
227-
),
228-
'/dist/output.meta.js': Fixtures.loadHeadersHeaders,
229-
});
230-
});
231-
});
232205
});

0 commit comments

Comments
 (0)