@openmrs/esm-app-shell 10.0.1-pre.5389 → 10.0.1-pre.5396

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.
@@ -0,0 +1,83 @@
1
+ // The dev server serves what it builds, proxies files it doesn't have to a real distribution, and falls
2
+ // back to the locally built `index.html` for everything else. That last split is the one worth pinning:
3
+ // misclassify a route as a file and the browser is quietly handed the upstream's shell instead of this one.
4
+ import { resolve } from 'node:path';
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ const shellRoot = resolve(__dirname, '..');
8
+ const spaPath = '/openmrs/spa';
9
+
10
+ /** The directory `openmrs assemble` gives a frontend module, named for the package and its version. */
11
+ const moduleDir = 'openmrs-esm-home-app-11.1.1-pre.9638';
12
+
13
+ let proxy: Record<string, any> | undefined;
14
+
15
+ /**
16
+ * The proxy entry the dev server is actually configured with.
17
+ *
18
+ * Loaded from `shellRoot` because the config resolves paths and the styleguide stylesheet relative to
19
+ * its own directory.
20
+ */
21
+ function loadProxy() {
22
+ if (!proxy) {
23
+ const originalCwd = process.cwd();
24
+ process.chdir(shellRoot);
25
+
26
+ try {
27
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
28
+ const config = require('../rspack.config.js')({}, { mode: 'development' }) as Record<string, any>;
29
+ proxy = config.devServer.proxy[0];
30
+ } finally {
31
+ process.chdir(originalCwd);
32
+ }
33
+ }
34
+
35
+ return proxy!;
36
+ }
37
+
38
+ describe('the dev server proxy', () => {
39
+ it.each([
40
+ ['a chunk', `${spaPath}/${moduleDir}/4610.js`],
41
+ ['an extracted stylesheet', `${spaPath}/${moduleDir}/180.css`],
42
+ ['a source map', `${spaPath}/${moduleDir}/180.css.map`],
43
+ ['an image', `${spaPath}/${moduleDir}/9a3f2c1d.png`],
44
+ ['a font', `${spaPath}/${moduleDir}/font.woff2`],
45
+ ['translations', `${spaPath}/${moduleDir}/en.json`],
46
+ ['a root-level asset', `${spaPath}/importmap.json`],
47
+ ['the favicon', `${spaPath}/favicon.ico`],
48
+ ['an asset with a cache-busting query', `${spaPath}/${moduleDir}/180.css?v=2`],
49
+ ])('proxies %s', (_, path) => {
50
+ expect(loadProxy().context(path)).toBe(true);
51
+ });
52
+
53
+ it.each([
54
+ ['a page', `${spaPath}/81239898/patient-chart`],
55
+ ['a patient chart', `${spaPath}/patient/2b0f0cba/chart`],
56
+ ['the home page', `${spaPath}/home`],
57
+ ['the SPA root', `${spaPath}/`],
58
+ // `basename()` sees the query, so any dot in one used to make these look like files.
59
+ ['a search whose query holds a dot', `${spaPath}/search?query=john.doe`],
60
+ ['a page whose query holds a dot', `${spaPath}/81239898/patient-chart?tab=vitals.summary`],
61
+ ])('leaves %s to the locally built index.html', (_, path) => {
62
+ expect(loadProxy().context(path)).toBe(false);
63
+ });
64
+
65
+ it.each([
66
+ ['the REST API', '/openmrs/ws/rest/v1/session'],
67
+ ['the FHIR API', '/openmrs/ws/fhir2/R4/Patient?name=john'],
68
+ ])('proxies %s', (_, path) => {
69
+ expect(loadProxy().context(path)).toBe(true);
70
+ });
71
+
72
+ it.each([
73
+ ['an empty path', ''],
74
+ ['a path it does not own', '/other/thing.js'],
75
+ ])('ignores %s', (_, path) => {
76
+ expect(loadProxy().context(path)).toBe(false);
77
+ });
78
+
79
+ // A remote's assets sit under its own directory, so anything but a verbatim path 404s.
80
+ it('proxies paths verbatim', () => {
81
+ expect(loadProxy().pathRewrite).toBeUndefined();
82
+ });
83
+ });