@mintlify/previewing 4.0.1463 → 4.0.1465
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.
|
@@ -100,18 +100,21 @@ const fakeBuild = async ({ islands, outDir, }) => {
|
|
|
100
100
|
missingLocalFiles: [],
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
|
-
const until = async (condition) => {
|
|
104
|
-
for (let i = 0; i < 300; i++) {
|
|
105
|
-
if (condition())
|
|
106
|
-
return;
|
|
107
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
108
|
-
}
|
|
109
|
-
throw new Error('condition not met');
|
|
110
|
-
};
|
|
111
103
|
describe('package snippet membership in the mint dev watcher', () => {
|
|
112
104
|
let root;
|
|
113
105
|
let dev;
|
|
114
106
|
let builds;
|
|
107
|
+
const buildWaiters = new Set();
|
|
108
|
+
const untilBuilt = (count) => new Promise((resolve) => {
|
|
109
|
+
const check = () => {
|
|
110
|
+
if (builds < count)
|
|
111
|
+
return;
|
|
112
|
+
buildWaiters.delete(check);
|
|
113
|
+
resolve();
|
|
114
|
+
};
|
|
115
|
+
buildWaiters.add(check);
|
|
116
|
+
check();
|
|
117
|
+
});
|
|
115
118
|
const docs = (file) => join(testPaths.cmd, file);
|
|
116
119
|
const output = (file) => fse.readFile(join(file.startsWith('snippets/') ? testPaths.public : testPaths.props, file), 'utf8');
|
|
117
120
|
const outputs = (files) => Promise.all(files.map(output));
|
|
@@ -147,7 +150,7 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
147
150
|
const editSnippet = async (file, content) => {
|
|
148
151
|
const settled = builds + 1;
|
|
149
152
|
await saveSnippet(file, content);
|
|
150
|
-
await
|
|
153
|
+
await untilBuilt(settled);
|
|
151
154
|
};
|
|
152
155
|
const compilePage = async (file) => {
|
|
153
156
|
const { pageContent } = await createPage(file, await fse.readFile(docs(file), 'utf8'), testPaths.cmd, [], []);
|
|
@@ -193,6 +196,19 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
193
196
|
await generatePagesWithImports(new Set(snippets));
|
|
194
197
|
builds = 0;
|
|
195
198
|
};
|
|
199
|
+
beforeAll(async () => {
|
|
200
|
+
// getMdx loads its syntax highlighter on first use. Pay that once here instead of in
|
|
201
|
+
// whichever test renders first.
|
|
202
|
+
await getMdx({
|
|
203
|
+
path: 'warm-up',
|
|
204
|
+
content: '',
|
|
205
|
+
metadata: {},
|
|
206
|
+
snippets: [],
|
|
207
|
+
subdomain: 'local',
|
|
208
|
+
codeStyling: undefined,
|
|
209
|
+
tailwindSelectors: [],
|
|
210
|
+
});
|
|
211
|
+
});
|
|
196
212
|
beforeEach(async () => {
|
|
197
213
|
root = await mkdtemp(join(tmpdir(), 'packages-dev-snippets-'));
|
|
198
214
|
testPaths.cmd = join(root, 'docs');
|
|
@@ -211,6 +227,8 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
211
227
|
propsPath: testPaths.props,
|
|
212
228
|
onRebuilt: () => {
|
|
213
229
|
builds++;
|
|
230
|
+
for (const check of buildWaiters)
|
|
231
|
+
check();
|
|
214
232
|
},
|
|
215
233
|
regenerateSnippets: regenerateAllSnippets,
|
|
216
234
|
reporter: {
|
|
@@ -221,11 +239,12 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
221
239
|
islandErrors: () => { },
|
|
222
240
|
configError: () => { },
|
|
223
241
|
},
|
|
224
|
-
debounceMs:
|
|
242
|
+
debounceMs: 0,
|
|
225
243
|
build: fakeBuild,
|
|
226
244
|
});
|
|
227
245
|
});
|
|
228
246
|
afterEach(async () => {
|
|
247
|
+
buildWaiters.clear();
|
|
229
248
|
releaseBuild();
|
|
230
249
|
await dev.close();
|
|
231
250
|
setPackageImportOptions(undefined);
|
|
@@ -282,7 +301,7 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
282
301
|
const settled = builds + 1;
|
|
283
302
|
await fse.remove(docs('snippets/toggle.jsx'));
|
|
284
303
|
await dev.onFileChange('snippets/toggle.jsx', 'snippet-v2');
|
|
285
|
-
await
|
|
304
|
+
await untilBuilt(settled);
|
|
286
305
|
expect(await packageSnippets()).toEqual([]);
|
|
287
306
|
});
|
|
288
307
|
it('keeps a package snippet that fails to parse on islands when package.json and docs.json are saved', async () => {
|
|
@@ -291,10 +310,12 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
291
310
|
const initial = await outputs(TOGGLE_OUTPUTS);
|
|
292
311
|
await editSnippet('snippets/toggle.jsx', BROKEN_TOGGLE);
|
|
293
312
|
const broken = await outputs(TOGGLE_OUTPUTS);
|
|
313
|
+
const manifestBuilt = builds + 1;
|
|
294
314
|
await fse.outputJson(docs('package.json'), { dependencies: { '@acme/ui': '1.0.0' } });
|
|
295
315
|
await dev.onFileChange('package.json', getFileCategory('package.json'));
|
|
296
316
|
await fse.outputJson(docs('docs.json'), { name: 'Docs', packages: {} });
|
|
297
317
|
await dev.onFileChange('docs.json', 'docsConfig');
|
|
318
|
+
await untilBuilt(manifestBuilt);
|
|
298
319
|
expect(await packageSnippets()).toEqual(islands);
|
|
299
320
|
expect(await outputs(TOGGLE_OUTPUTS)).toEqual(broken);
|
|
300
321
|
expectKept(await output('snippets/wrapper.jsx'), TOGGLE_IMPORT, 'A parsing error occurred');
|
|
@@ -361,7 +382,7 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
361
382
|
expect(island).toEqual({ prefix: `mi-${id}-` });
|
|
362
383
|
}
|
|
363
384
|
releaseBuild();
|
|
364
|
-
await
|
|
385
|
+
await untilBuilt(settled);
|
|
365
386
|
const built = { ...(await render('toggle-page.mdx')), ...(await render('wrapper-page.mdx')) };
|
|
366
387
|
expect(Object.keys(built)).toEqual(Object.keys(pending));
|
|
367
388
|
for (const [id, island] of Object.entries(built)) {
|
|
@@ -384,7 +405,7 @@ describe('package snippet membership in the mint dev watcher', () => {
|
|
|
384
405
|
const [id] = Object.keys(pending);
|
|
385
406
|
expect(pending).toEqual({ [id ?? '']: { prefix: `mi-${id}-` } });
|
|
386
407
|
releaseBuild();
|
|
387
|
-
await
|
|
408
|
+
await untilBuilt(settled);
|
|
388
409
|
expect(await render('badge-page.mdx')).toEqual({
|
|
389
410
|
[id ?? '']: { prefix: `mi-${id}-`, html: `<svg data-id="${id}"></svg>` },
|
|
390
411
|
});
|
|
@@ -1201,7 +1201,7 @@ export const Card = () => <LineChart width={400} height={200} data={[{ v: 1 }]}
|
|
|
1201
1201
|
rebuilt = 0;
|
|
1202
1202
|
mode.throwing = true;
|
|
1203
1203
|
await duringNextBuild(() => write(css('.card { color: blue; }\n')), () => write({ file, content: 'x', category: 'staticFile' }));
|
|
1204
|
-
await until(() => rebuilt >=
|
|
1204
|
+
await until(() => rebuilt >= builds);
|
|
1205
1205
|
await settle();
|
|
1206
1206
|
expect(rebuilt).toBe(builds);
|
|
1207
1207
|
expect(dev.getStatus().state).toBe('failed');
|