@inlang/sdk 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/solidAdapter.d.ts +2 -2
- package/dist/adapter/solidAdapter.d.ts.map +1 -1
- package/dist/adapter/solidAdapter.js +2 -2
- package/dist/adapter/solidAdapter.test.js +68 -78
- package/dist/api.d.ts +10 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.test-d.d.ts +2 -0
- package/dist/api.test-d.d.ts.map +1 -0
- package/dist/api.test-d.js +4 -0
- package/dist/createMessageLintReportsQuery.d.ts +2 -2
- package/dist/createMessageLintReportsQuery.d.ts.map +1 -1
- package/dist/createMessageLintReportsQuery.js +11 -11
- package/dist/createMessagesQuery.js +1 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lint/message/lintMessages.d.ts +3 -7
- package/dist/lint/message/lintMessages.d.ts.map +1 -1
- package/dist/lint/message/lintMessages.test.js +38 -36
- package/dist/lint/message/lintSingleMessage.d.ts +3 -7
- package/dist/lint/message/lintSingleMessage.d.ts.map +1 -1
- package/dist/lint/message/lintSingleMessage.js +10 -10
- package/dist/lint/message/lintSingleMessage.test.js +71 -65
- package/dist/{openInlangProject.d.ts → loadProject.d.ts} +3 -3
- package/dist/loadProject.d.ts.map +1 -0
- package/dist/{openInlangProject.js → loadProject.js} +70 -66
- package/dist/loadProject.test.d.ts +2 -0
- package/dist/loadProject.test.d.ts.map +1 -0
- package/dist/{openInlangProject.test.js → loadProject.test.js} +160 -176
- package/dist/parseConfig.d.ts +2 -2
- package/dist/parseConfig.d.ts.map +1 -1
- package/dist/parseConfig.js +3 -3
- package/dist/resolve-modules/import.js +1 -1
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +1 -1
- package/dist/resolve-modules/plugins/errors.d.ts +1 -1
- package/dist/resolve-modules/plugins/errors.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/resolvePlugins.js +15 -15
- package/dist/resolve-modules/plugins/resolvePlugins.test.js +55 -94
- package/dist/resolve-modules/plugins/types.d.ts +1 -1
- package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/types.test.js +10 -14
- package/dist/resolve-modules/resolveModules.d.ts.map +1 -1
- package/dist/resolve-modules/resolveModules.js +9 -9
- package/dist/resolve-modules/resolveModules.test.js +28 -42
- package/dist/resolve-modules/types.d.ts +3 -3
- package/dist/resolve-modules/types.d.ts.map +1 -1
- package/dist/versionedInterfaces.d.ts +1 -1
- package/dist/versionedInterfaces.d.ts.map +1 -1
- package/dist/versionedInterfaces.js +1 -1
- package/package.json +3 -3
- package/src/adapter/solidAdapter.test.ts +77 -87
- package/src/adapter/solidAdapter.ts +4 -4
- package/src/api.test-d.ts +8 -0
- package/src/api.ts +10 -6
- package/src/createMessageLintReportsQuery.ts +15 -20
- package/src/createMessagesQuery.ts +1 -1
- package/src/errors.ts +6 -6
- package/src/index.ts +4 -4
- package/src/lint/message/lintMessages.test.ts +38 -36
- package/src/lint/message/lintMessages.ts +3 -11
- package/src/lint/message/lintSingleMessage.test.ts +71 -65
- package/src/lint/message/lintSingleMessage.ts +13 -21
- package/src/{openInlangProject.test.ts → loadProject.test.ts} +165 -181
- package/src/{openInlangProject.ts → loadProject.ts} +81 -82
- package/src/parseConfig.ts +5 -3
- package/src/resolve-modules/import.ts +1 -1
- package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +1 -1
- package/src/resolve-modules/plugins/errors.ts +1 -1
- package/src/resolve-modules/plugins/resolvePlugins.test.ts +55 -94
- package/src/resolve-modules/plugins/resolvePlugins.ts +19 -19
- package/src/resolve-modules/plugins/types.test.ts +11 -15
- package/src/resolve-modules/plugins/types.ts +1 -1
- package/src/resolve-modules/resolveModules.test.ts +29 -43
- package/src/resolve-modules/resolveModules.ts +11 -9
- package/src/resolve-modules/types.ts +3 -3
- package/src/versionedInterfaces.ts +1 -1
- package/dist/openInlangProject.d.ts.map +0 -1
- package/dist/openInlangProject.test.d.ts +0 -2
- package/dist/openInlangProject.test.d.ts.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { describe, it, expect, vi } from "vitest"
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import { loadProject } from "./loadProject.js"
|
|
4
|
+
import type { ProjectSettings, Plugin, MessageLintRule, Message } from "./versionedInterfaces.js"
|
|
5
5
|
import type { ImportFunction } from "./resolve-modules/index.js"
|
|
6
6
|
import type { InlangModule } from "@inlang/module"
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
ProjectSettingsFileJSONSyntaxError,
|
|
9
|
+
ProjectSettingsFileNotFoundError,
|
|
10
|
+
ProjectSettingsInvalidError,
|
|
11
11
|
} from "./errors.js"
|
|
12
12
|
import { createNodeishMemoryFs } from "@lix-js/fs"
|
|
13
13
|
|
|
@@ -19,31 +19,27 @@ const getValue = <T>(subscribable: { subscribe: (subscriber: (value: T) => void)
|
|
|
19
19
|
return value!
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const settings: ProjectSettings = {
|
|
23
23
|
sourceLanguageTag: "en",
|
|
24
24
|
languageTags: ["en"],
|
|
25
25
|
modules: ["plugin.js", "lintRule.js"],
|
|
26
|
-
|
|
27
|
-
"project.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
variableReferencePattern: ["{", "}"],
|
|
33
|
-
},
|
|
26
|
+
messageLintRuleLevels: {
|
|
27
|
+
"messageLintRule.project.missingTranslation": "error",
|
|
28
|
+
},
|
|
29
|
+
"plugin.project.i18next": {
|
|
30
|
+
pathPattern: "./examples/example01/{languageTag}.json",
|
|
31
|
+
variableReferencePattern: ["{", "}"],
|
|
34
32
|
},
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
const mockPlugin: Plugin = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
displayName: { en: "Mock Plugin" },
|
|
42
|
-
},
|
|
36
|
+
id: "plugin.project.i18next",
|
|
37
|
+
description: { en: "Mock plugin description" },
|
|
38
|
+
displayName: { en: "Mock Plugin" },
|
|
43
39
|
loadMessages: () => exampleMessages,
|
|
44
40
|
saveMessages: () => undefined as any,
|
|
45
41
|
addCustomApi: () => ({
|
|
46
|
-
"app.
|
|
42
|
+
"app.project.ideExtension": {
|
|
47
43
|
messageReferenceMatcher: (text: string) => text as any,
|
|
48
44
|
},
|
|
49
45
|
}),
|
|
@@ -86,12 +82,10 @@ const exampleMessages: Message[] = [
|
|
|
86
82
|
]
|
|
87
83
|
|
|
88
84
|
const mockMessageLintRule: MessageLintRule = {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
message: () => undefined,
|
|
85
|
+
id: "messageLintRule.project.mock",
|
|
86
|
+
description: { en: "Mock lint rule description" },
|
|
87
|
+
displayName: { en: "Mock Lint Rule" },
|
|
88
|
+
run: () => undefined,
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
const _import: ImportFunction = async (name) =>
|
|
@@ -102,77 +96,77 @@ const _import: ImportFunction = async (name) =>
|
|
|
102
96
|
// ------------------------------------------------------------------------------------------------
|
|
103
97
|
|
|
104
98
|
describe("initialization", () => {
|
|
105
|
-
describe("
|
|
106
|
-
it("should return an error if
|
|
99
|
+
describe("settings", () => {
|
|
100
|
+
it("should return an error if settings file is not found", async () => {
|
|
107
101
|
const fs = createNodeishMemoryFs()
|
|
108
102
|
|
|
109
|
-
const
|
|
110
|
-
|
|
103
|
+
const project = await loadProject({
|
|
104
|
+
settingsFilePath: "./test.json",
|
|
111
105
|
nodeishFs: fs,
|
|
112
106
|
_import,
|
|
113
107
|
})
|
|
114
108
|
|
|
115
|
-
expect(
|
|
109
|
+
expect(project.errors()![0]).toBeInstanceOf(ProjectSettingsFileNotFoundError)
|
|
116
110
|
})
|
|
117
111
|
|
|
118
|
-
it("should return an error if
|
|
112
|
+
it("should return an error if settings file is not a valid JSON", async () => {
|
|
119
113
|
const fs = await createNodeishMemoryFs()
|
|
120
114
|
await fs.writeFile("./project.inlang.json", "invalid json")
|
|
121
115
|
|
|
122
|
-
const
|
|
123
|
-
|
|
116
|
+
const project = await loadProject({
|
|
117
|
+
settingsFilePath: "./project.inlang.json",
|
|
124
118
|
nodeishFs: fs,
|
|
125
119
|
_import,
|
|
126
120
|
})
|
|
127
121
|
|
|
128
|
-
expect(
|
|
122
|
+
expect(project.errors()![0]).toBeInstanceOf(ProjectSettingsFileJSONSyntaxError)
|
|
129
123
|
})
|
|
130
124
|
|
|
131
|
-
it("should return an error if
|
|
125
|
+
it("should return an error if settings file is does not match schema", async () => {
|
|
132
126
|
const fs = await createNodeishMemoryFs()
|
|
133
127
|
await fs.writeFile("./project.inlang.json", JSON.stringify({}))
|
|
134
128
|
|
|
135
|
-
const
|
|
136
|
-
|
|
129
|
+
const project = await loadProject({
|
|
130
|
+
settingsFilePath: "./project.inlang.json",
|
|
137
131
|
nodeishFs: fs,
|
|
138
132
|
_import,
|
|
139
133
|
})
|
|
140
134
|
|
|
141
|
-
expect(
|
|
135
|
+
expect(project.errors()![0]).toBeInstanceOf(ProjectSettingsInvalidError)
|
|
142
136
|
})
|
|
143
137
|
|
|
144
|
-
it("should return the parsed
|
|
138
|
+
it("should return the parsed settings", async () => {
|
|
145
139
|
const fs = await createNodeishMemoryFs()
|
|
146
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
147
|
-
const
|
|
148
|
-
|
|
140
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
141
|
+
const project = await loadProject({
|
|
142
|
+
settingsFilePath: "./project.inlang.json",
|
|
149
143
|
nodeishFs: fs,
|
|
150
144
|
_import,
|
|
151
145
|
})
|
|
152
146
|
|
|
153
|
-
expect(
|
|
147
|
+
expect(project.settings()).toStrictEqual(settings)
|
|
154
148
|
})
|
|
155
149
|
|
|
156
|
-
it("should not re-write the
|
|
150
|
+
it("should not re-write the settings to disk when initializing", async () => {
|
|
157
151
|
const fs = await createNodeishMemoryFs()
|
|
158
|
-
const
|
|
159
|
-
await fs.writeFile("./project.inlang.json",
|
|
152
|
+
const settingsWithDeifferentFormatting = JSON.stringify(settings, undefined, 4)
|
|
153
|
+
await fs.writeFile("./project.inlang.json", settingsWithDeifferentFormatting)
|
|
160
154
|
|
|
161
|
-
const
|
|
162
|
-
|
|
155
|
+
const project = await loadProject({
|
|
156
|
+
settingsFilePath: "./project.inlang.json",
|
|
163
157
|
nodeishFs: fs,
|
|
164
158
|
_import,
|
|
165
159
|
})
|
|
166
160
|
|
|
167
|
-
const
|
|
168
|
-
expect(
|
|
161
|
+
const settingsOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
|
|
162
|
+
expect(settingsOnDisk).toBe(settingsWithDeifferentFormatting)
|
|
169
163
|
|
|
170
|
-
|
|
171
|
-
// TODO: how can we await `
|
|
164
|
+
project.setSettings(project.settings())
|
|
165
|
+
// TODO: how can we await `setsettings` correctly
|
|
172
166
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
173
167
|
|
|
174
|
-
const
|
|
175
|
-
expect(
|
|
168
|
+
const newsettingsOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
|
|
169
|
+
expect(newsettingsOnDisk).not.toBe(settingsWithDeifferentFormatting)
|
|
176
170
|
})
|
|
177
171
|
})
|
|
178
172
|
|
|
@@ -184,15 +178,15 @@ describe("initialization", () => {
|
|
|
184
178
|
} satisfies InlangModule)
|
|
185
179
|
|
|
186
180
|
const fs = createNodeishMemoryFs()
|
|
187
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
181
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
188
182
|
|
|
189
|
-
const
|
|
190
|
-
|
|
183
|
+
const project = await loadProject({
|
|
184
|
+
settingsFilePath: "./project.inlang.json",
|
|
191
185
|
nodeishFs: fs,
|
|
192
186
|
_import: $badImport,
|
|
193
187
|
})
|
|
194
188
|
|
|
195
|
-
expect(
|
|
189
|
+
expect(project.errors()).not.toHaveLength(0)
|
|
196
190
|
})
|
|
197
191
|
// it.todo("should throw if lintRules contain errors ???")
|
|
198
192
|
// it.todo("should return meta data")
|
|
@@ -202,7 +196,7 @@ describe("initialization", () => {
|
|
|
202
196
|
|
|
203
197
|
describe("flow", () => {
|
|
204
198
|
it.todo("should not call functions multiple times")
|
|
205
|
-
it.todo("should load modules after
|
|
199
|
+
it.todo("should load modules after settings")
|
|
206
200
|
it.todo("should not load messages")
|
|
207
201
|
it.todo("should not call lint")
|
|
208
202
|
})
|
|
@@ -213,60 +207,63 @@ describe("initialization", () => {
|
|
|
213
207
|
})
|
|
214
208
|
|
|
215
209
|
describe("functionality", () => {
|
|
216
|
-
describe("
|
|
217
|
-
it("should return the
|
|
210
|
+
describe("settings", () => {
|
|
211
|
+
it("should return the settings", async () => {
|
|
218
212
|
const fs = await createNodeishMemoryFs()
|
|
219
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
220
|
-
const
|
|
221
|
-
|
|
213
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
214
|
+
const project = await loadProject({
|
|
215
|
+
settingsFilePath: "./project.inlang.json",
|
|
222
216
|
nodeishFs: fs,
|
|
223
217
|
_import,
|
|
224
218
|
})
|
|
225
219
|
|
|
226
|
-
expect(getValue(
|
|
220
|
+
expect(getValue(project.settings)).toStrictEqual(settings)
|
|
227
221
|
})
|
|
228
222
|
|
|
229
|
-
it("should set a new
|
|
223
|
+
it("should set a new settings", async () => {
|
|
230
224
|
const fs = await createNodeishMemoryFs()
|
|
231
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
232
|
-
const
|
|
233
|
-
|
|
225
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
226
|
+
const project = await loadProject({
|
|
227
|
+
settingsFilePath: "./project.inlang.json",
|
|
234
228
|
nodeishFs: fs,
|
|
235
229
|
_import,
|
|
236
230
|
})
|
|
237
231
|
|
|
238
|
-
expect(
|
|
232
|
+
expect(project.settings()).toStrictEqual(settings)
|
|
239
233
|
|
|
240
|
-
|
|
241
|
-
expect(getValue(
|
|
242
|
-
expect(
|
|
234
|
+
project.setSettings({ ...settings, languageTags: ["en", "de"] })
|
|
235
|
+
expect(getValue(project.settings)).toStrictEqual({ ...settings, languageTags: ["en", "de"] })
|
|
236
|
+
expect(project.settings()!.languageTags).toStrictEqual(["en", "de"])
|
|
243
237
|
|
|
244
|
-
|
|
245
|
-
expect(getValue(
|
|
246
|
-
|
|
238
|
+
project.setSettings({ ...settings, languageTags: ["en", "de", "fr"] })
|
|
239
|
+
expect(getValue(project.settings)).toStrictEqual({
|
|
240
|
+
...settings,
|
|
241
|
+
languageTags: ["en", "de", "fr"],
|
|
242
|
+
})
|
|
243
|
+
expect(project.settings()!.languageTags).toStrictEqual(["en", "de", "fr"])
|
|
247
244
|
})
|
|
248
245
|
})
|
|
249
246
|
|
|
250
|
-
describe("
|
|
251
|
-
it("should fail if
|
|
247
|
+
describe("setSettings", () => {
|
|
248
|
+
it("should fail if settings is not valid", async () => {
|
|
252
249
|
const fs = await createNodeishMemoryFs()
|
|
253
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
254
|
-
const
|
|
255
|
-
|
|
250
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
251
|
+
const project = await loadProject({
|
|
252
|
+
settingsFilePath: "./project.inlang.json",
|
|
256
253
|
nodeishFs: fs,
|
|
257
254
|
_import,
|
|
258
255
|
})
|
|
259
256
|
|
|
260
|
-
const result =
|
|
257
|
+
const result = project.setSettings({} as ProjectSettings)
|
|
261
258
|
expect(result.data).toBeUndefined()
|
|
262
|
-
expect(result.error).toBeInstanceOf(
|
|
259
|
+
expect(result.error).toBeInstanceOf(ProjectSettingsInvalidError)
|
|
263
260
|
})
|
|
264
261
|
|
|
265
|
-
it("should write
|
|
262
|
+
it("should write settings to disk", async () => {
|
|
266
263
|
const fs = await createNodeishMemoryFs()
|
|
267
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
268
|
-
const
|
|
269
|
-
|
|
264
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
265
|
+
const project = await loadProject({
|
|
266
|
+
settingsFilePath: "./project.inlang.json",
|
|
270
267
|
nodeishFs: fs,
|
|
271
268
|
_import,
|
|
272
269
|
})
|
|
@@ -274,7 +271,7 @@ describe("functionality", () => {
|
|
|
274
271
|
const before = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
|
|
275
272
|
expect(before).toBeDefined()
|
|
276
273
|
|
|
277
|
-
const result =
|
|
274
|
+
const result = project.setSettings({ ...settings, languageTags: [] })
|
|
278
275
|
expect(result.data).toBeUndefined()
|
|
279
276
|
expect(result.error).toBeUndefined()
|
|
280
277
|
|
|
@@ -290,61 +287,61 @@ describe("functionality", () => {
|
|
|
290
287
|
describe("installed", () => {
|
|
291
288
|
it("should return the installed items", async () => {
|
|
292
289
|
const fs = createNodeishMemoryFs()
|
|
293
|
-
const
|
|
290
|
+
const settings: ProjectSettings = {
|
|
294
291
|
sourceLanguageTag: "en",
|
|
295
292
|
languageTags: ["en"],
|
|
296
293
|
modules: ["plugin.js", "lintRule.js"],
|
|
297
|
-
settings: {},
|
|
298
294
|
}
|
|
299
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
300
|
-
const
|
|
301
|
-
|
|
295
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
296
|
+
const project = await loadProject({
|
|
297
|
+
settingsFilePath: "./project.inlang.json",
|
|
302
298
|
nodeishFs: fs,
|
|
303
299
|
_import,
|
|
304
300
|
})
|
|
305
301
|
|
|
306
|
-
expect(
|
|
307
|
-
|
|
308
|
-
|
|
302
|
+
expect(project.installed.plugins()[0]).toStrictEqual({
|
|
303
|
+
id: mockPlugin.id,
|
|
304
|
+
description: mockPlugin.description,
|
|
305
|
+
displayName: mockPlugin.displayName,
|
|
306
|
+
module: settings.modules[0],
|
|
309
307
|
})
|
|
310
308
|
|
|
311
|
-
expect(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
309
|
+
expect(project.installed.messageLintRules()[0]).toEqual({
|
|
310
|
+
id: mockMessageLintRule.id,
|
|
311
|
+
description: mockMessageLintRule.description,
|
|
312
|
+
displayName: mockMessageLintRule.displayName,
|
|
313
|
+
module: settings.modules[1],
|
|
314
|
+
level: "warning",
|
|
315
315
|
})
|
|
316
316
|
})
|
|
317
317
|
|
|
318
|
-
it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the
|
|
318
|
+
it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the settings", async () => {
|
|
319
319
|
const fs = createNodeishMemoryFs()
|
|
320
320
|
|
|
321
|
-
const
|
|
321
|
+
const settings: ProjectSettings = {
|
|
322
322
|
sourceLanguageTag: "en",
|
|
323
323
|
languageTags: ["en"],
|
|
324
324
|
modules: ["plugin.js", "lintRule.js"],
|
|
325
|
-
settings: {},
|
|
326
325
|
}
|
|
327
326
|
|
|
328
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
327
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
329
328
|
|
|
330
|
-
const
|
|
331
|
-
|
|
329
|
+
const project = await loadProject({
|
|
330
|
+
settingsFilePath: "./project.inlang.json",
|
|
332
331
|
nodeishFs: fs,
|
|
333
332
|
_import,
|
|
334
333
|
})
|
|
335
334
|
|
|
336
|
-
expect(
|
|
335
|
+
expect(project.installed.messageLintRules()[0]?.level).toBe("warning")
|
|
337
336
|
})
|
|
338
337
|
|
|
339
338
|
// yep, this is a typical "hm, we have a bug here, let's write a test for it" test
|
|
340
339
|
it("should return lint reports if disabled is not set", async () => {
|
|
341
340
|
const _mockLintRule: MessageLintRule = {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
},
|
|
347
|
-
message: ({ report }) => {
|
|
341
|
+
id: "messageLintRule.namespace.mock",
|
|
342
|
+
description: { en: "Mock lint rule description" },
|
|
343
|
+
displayName: { en: "Mock Lint Rule" },
|
|
344
|
+
run: ({ report }) => {
|
|
348
345
|
report({
|
|
349
346
|
messageId: "some-message-1",
|
|
350
347
|
languageTag: "en",
|
|
@@ -353,11 +350,9 @@ describe("functionality", () => {
|
|
|
353
350
|
},
|
|
354
351
|
}
|
|
355
352
|
const _mockPlugin: Plugin = {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
displayName: { en: "Mock Plugin" },
|
|
360
|
-
},
|
|
353
|
+
id: "plugin.project.i18next",
|
|
354
|
+
description: { en: "Mock plugin description" },
|
|
355
|
+
displayName: { en: "Mock Plugin" },
|
|
361
356
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
362
357
|
saveMessages: () => undefined,
|
|
363
358
|
}
|
|
@@ -368,8 +363,7 @@ describe("functionality", () => {
|
|
|
368
363
|
sourceLanguageTag: "en",
|
|
369
364
|
languageTags: ["en"],
|
|
370
365
|
modules: ["plugin.js", "lintRule.js"],
|
|
371
|
-
|
|
372
|
-
} satisfies ProjectConfig),
|
|
366
|
+
} satisfies ProjectSettings),
|
|
373
367
|
)
|
|
374
368
|
|
|
375
369
|
const _import: ImportFunction = async (name) => {
|
|
@@ -377,27 +371,25 @@ describe("functionality", () => {
|
|
|
377
371
|
default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
|
|
378
372
|
} satisfies InlangModule
|
|
379
373
|
}
|
|
380
|
-
const
|
|
381
|
-
|
|
374
|
+
const project = await loadProject({
|
|
375
|
+
settingsFilePath: "./project.inlang.json",
|
|
382
376
|
nodeishFs: fs,
|
|
383
377
|
_import,
|
|
384
378
|
})
|
|
385
379
|
|
|
386
380
|
await new Promise((resolve) => setTimeout(resolve, 510))
|
|
387
381
|
|
|
388
|
-
expect(
|
|
389
|
-
expect(
|
|
390
|
-
expect(
|
|
382
|
+
expect(project.query.messageLintReports.getAll()).toHaveLength(1)
|
|
383
|
+
expect(project.query.messageLintReports.getAll()?.[0]?.ruleId).toBe(_mockLintRule.id)
|
|
384
|
+
expect(project.installed.messageLintRules()).toHaveLength(1)
|
|
391
385
|
})
|
|
392
386
|
|
|
393
387
|
it("should return lint reports for a single message", async () => {
|
|
394
388
|
const _mockLintRule: MessageLintRule = {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
},
|
|
400
|
-
message: ({ report }) => {
|
|
389
|
+
id: "messageLintRule.namepsace.mock",
|
|
390
|
+
description: { en: "Mock lint rule description" },
|
|
391
|
+
displayName: { en: "Mock Lint Rule" },
|
|
392
|
+
run: ({ report }) => {
|
|
401
393
|
report({
|
|
402
394
|
messageId: "some-message",
|
|
403
395
|
languageTag: "en",
|
|
@@ -406,23 +398,20 @@ describe("functionality", () => {
|
|
|
406
398
|
},
|
|
407
399
|
}
|
|
408
400
|
const _mockPlugin: Plugin = {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
displayName: { en: "Mock Plugin" },
|
|
413
|
-
},
|
|
401
|
+
id: "plugin.project.i18next",
|
|
402
|
+
description: { en: "Mock plugin description" },
|
|
403
|
+
displayName: { en: "Mock Plugin" },
|
|
414
404
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
415
405
|
saveMessages: () => undefined,
|
|
416
406
|
}
|
|
417
407
|
const fs = await createNodeishMemoryFs()
|
|
418
408
|
await fs.writeFile(
|
|
419
|
-
"./
|
|
409
|
+
"./project.settings.json",
|
|
420
410
|
JSON.stringify({
|
|
421
411
|
sourceLanguageTag: "en",
|
|
422
412
|
languageTags: ["en"],
|
|
423
413
|
modules: ["plugin.js", "lintRule.js"],
|
|
424
|
-
|
|
425
|
-
} satisfies ProjectConfig),
|
|
414
|
+
} satisfies ProjectSettings),
|
|
426
415
|
)
|
|
427
416
|
const _import: ImportFunction = async (name) => {
|
|
428
417
|
return {
|
|
@@ -430,8 +419,8 @@ describe("functionality", () => {
|
|
|
430
419
|
} satisfies InlangModule
|
|
431
420
|
}
|
|
432
421
|
|
|
433
|
-
const
|
|
434
|
-
|
|
422
|
+
const project = await loadProject({
|
|
423
|
+
settingsFilePath: "./project.settings.json",
|
|
435
424
|
nodeishFs: fs,
|
|
436
425
|
_import,
|
|
437
426
|
})
|
|
@@ -439,7 +428,7 @@ describe("functionality", () => {
|
|
|
439
428
|
await new Promise((resolve) => setTimeout(resolve, 510))
|
|
440
429
|
|
|
441
430
|
expect(
|
|
442
|
-
|
|
431
|
+
project.query.messageLintReports.get({ where: { messageId: "some-message" } }),
|
|
443
432
|
).toHaveLength(1)
|
|
444
433
|
})
|
|
445
434
|
})
|
|
@@ -447,13 +436,13 @@ describe("functionality", () => {
|
|
|
447
436
|
describe("errors", () => {
|
|
448
437
|
it("should return the errors", async () => {
|
|
449
438
|
const fs = await createNodeishMemoryFs()
|
|
450
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
451
|
-
const
|
|
452
|
-
|
|
439
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
440
|
+
const project = await loadProject({
|
|
441
|
+
settingsFilePath: "./project.inlang.json",
|
|
453
442
|
nodeishFs: fs,
|
|
454
443
|
_import,
|
|
455
444
|
})
|
|
456
|
-
|
|
445
|
+
project.errors.subscribe((errors) => {
|
|
457
446
|
expect(errors).toStrictEqual([])
|
|
458
447
|
})
|
|
459
448
|
})
|
|
@@ -462,15 +451,15 @@ describe("functionality", () => {
|
|
|
462
451
|
describe("customApi", () => {
|
|
463
452
|
it("should return the app specific api", async () => {
|
|
464
453
|
const fs = await createNodeishMemoryFs()
|
|
465
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
466
|
-
const
|
|
467
|
-
|
|
454
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
455
|
+
const project = await loadProject({
|
|
456
|
+
settingsFilePath: "./project.inlang.json",
|
|
468
457
|
nodeishFs: fs,
|
|
469
458
|
_import,
|
|
470
459
|
})
|
|
471
460
|
|
|
472
|
-
|
|
473
|
-
expect(api["app.
|
|
461
|
+
project.customApi.subscribe((api) => {
|
|
462
|
+
expect(api["app.project.ideExtension"]).toBeDefined()
|
|
474
463
|
})
|
|
475
464
|
})
|
|
476
465
|
})
|
|
@@ -478,20 +467,20 @@ describe("functionality", () => {
|
|
|
478
467
|
describe("messages", () => {
|
|
479
468
|
it("should return the messages", async () => {
|
|
480
469
|
const fs = await createNodeishMemoryFs()
|
|
481
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
482
|
-
const
|
|
483
|
-
|
|
470
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
471
|
+
const project = await loadProject({
|
|
472
|
+
settingsFilePath: "./project.inlang.json",
|
|
484
473
|
nodeishFs: fs,
|
|
485
474
|
_import,
|
|
486
475
|
})
|
|
487
476
|
|
|
488
|
-
expect(Object.values(
|
|
477
|
+
expect(Object.values(project.query.messages.getAll())).toEqual(exampleMessages)
|
|
489
478
|
})
|
|
490
479
|
})
|
|
491
480
|
|
|
492
481
|
describe("query", () => {
|
|
493
|
-
it("
|
|
494
|
-
const fs =
|
|
482
|
+
it("should call saveMessages() on updates", async () => {
|
|
483
|
+
const fs = createNodeishMemoryFs()
|
|
495
484
|
|
|
496
485
|
await fs.writeFile(
|
|
497
486
|
"./project.inlang.json",
|
|
@@ -499,10 +488,8 @@ describe("functionality", () => {
|
|
|
499
488
|
sourceLanguageTag: "en",
|
|
500
489
|
languageTags: ["en", "de"],
|
|
501
490
|
modules: ["plugin.js"],
|
|
502
|
-
|
|
503
|
-
"
|
|
504
|
-
pathPattern: "./resources/{languageTag}.json",
|
|
505
|
-
},
|
|
491
|
+
"plugin.project.json": {
|
|
492
|
+
pathPattern: "./resources/{languageTag}.json",
|
|
506
493
|
},
|
|
507
494
|
}),
|
|
508
495
|
)
|
|
@@ -512,11 +499,9 @@ describe("functionality", () => {
|
|
|
512
499
|
const mockSaveFn = vi.fn()
|
|
513
500
|
|
|
514
501
|
const _mockPlugin: Plugin = {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
displayName: { en: "Mock Plugin" },
|
|
519
|
-
},
|
|
502
|
+
id: "plugin.project.json",
|
|
503
|
+
description: { en: "Mock plugin description" },
|
|
504
|
+
displayName: { en: "Mock Plugin" },
|
|
520
505
|
loadMessages: () => exampleMessages,
|
|
521
506
|
saveMessages: mockSaveFn,
|
|
522
507
|
}
|
|
@@ -527,13 +512,13 @@ describe("functionality", () => {
|
|
|
527
512
|
} satisfies InlangModule
|
|
528
513
|
}
|
|
529
514
|
|
|
530
|
-
const
|
|
531
|
-
|
|
515
|
+
const project = await loadProject({
|
|
516
|
+
settingsFilePath: "./project.inlang.json",
|
|
532
517
|
nodeishFs: fs,
|
|
533
518
|
_import,
|
|
534
519
|
})
|
|
535
520
|
|
|
536
|
-
await
|
|
521
|
+
await project.query.messages.upsert({
|
|
537
522
|
where: { id: "a" },
|
|
538
523
|
data: {
|
|
539
524
|
id: "a",
|
|
@@ -563,7 +548,7 @@ describe("functionality", () => {
|
|
|
563
548
|
},
|
|
564
549
|
})
|
|
565
550
|
|
|
566
|
-
await
|
|
551
|
+
await project.query.messages.upsert({
|
|
567
552
|
where: { id: "b" },
|
|
568
553
|
data: {
|
|
569
554
|
id: "b",
|
|
@@ -662,38 +647,37 @@ describe("functionality", () => {
|
|
|
662
647
|
describe("lint", () => {
|
|
663
648
|
it.todo("should throw if lint reports are not initialized yet", async () => {
|
|
664
649
|
const fs = await createNodeishMemoryFs()
|
|
665
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
666
|
-
const
|
|
667
|
-
|
|
650
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
651
|
+
const project = await loadProject({
|
|
652
|
+
settingsFilePath: "./project.inlang.json",
|
|
668
653
|
nodeishFs: fs,
|
|
669
654
|
_import,
|
|
670
655
|
})
|
|
671
656
|
// TODO: test with real lint rules
|
|
672
657
|
try {
|
|
673
|
-
|
|
658
|
+
project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual(undefined))
|
|
674
659
|
throw new Error("Should not reach this")
|
|
675
660
|
} catch (e) {
|
|
676
661
|
expect((e as Error).message).toBe("lint not initialized yet")
|
|
677
662
|
}
|
|
678
663
|
})
|
|
679
664
|
it("should return the message lint reports", async () => {
|
|
680
|
-
const
|
|
665
|
+
const settings: ProjectSettings = {
|
|
681
666
|
sourceLanguageTag: "en",
|
|
682
667
|
languageTags: ["en"],
|
|
683
668
|
modules: ["lintRule.js"],
|
|
684
|
-
settings: {},
|
|
685
669
|
}
|
|
686
670
|
const fs = createNodeishMemoryFs()
|
|
687
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
688
|
-
const
|
|
689
|
-
|
|
671
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
|
|
672
|
+
const project = await loadProject({
|
|
673
|
+
settingsFilePath: "./project.inlang.json",
|
|
690
674
|
nodeishFs: fs,
|
|
691
675
|
_import: async () => ({
|
|
692
676
|
default: mockMessageLintRule,
|
|
693
677
|
}),
|
|
694
678
|
})
|
|
695
679
|
// TODO: test with real lint rules
|
|
696
|
-
|
|
680
|
+
project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual([]))
|
|
697
681
|
})
|
|
698
682
|
})
|
|
699
683
|
})
|