Skip to content

Commit f797cfb

Browse files
committed
test: adds unit test for doNotLoadConfig
1 parent fa55188 commit f797cfb

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

app-config-esbuild/src/__snapshots__/index.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ exports[`loads validation function 1`] = `
1414
"(()=>{var n=(typeof window==\\"undefined\\"?globalThis:window)||{},v={foo:\\"bar\\"},m=n._appConfig||v;(typeof n._appConfig==\\"undefined\\"||!Object.isFrozen(n._appConfig))&&(n._appConfig=m);function P(){let p={};return function(s){\\"use strict\\";s.exports=i,s.exports.default=i;var b={type:\\"object\\",additionalProperties:!1,properties:{foo:{type:\\"string\\"}},$schema:\\"http://json-schema.org/draft-07/schema#\\"};function i(o,t){\\"use strict\\";if(t)var a=t.dataPath,g=t.parentData,h=t.parentDataProperty,y=t.rootData;else var a=\\"\\",g=void 0,h=void 0,y=o;var e=null,r=0;if(o&&typeof o==\\"object\\"&&!Array.isArray(o)){for(var f in o)if(f!==\\"foo\\"){var d={keyword:\\"additionalProperties\\",dataPath:a,schemaPath:\\"#/additionalProperties\\",params:{additionalProperty:f},message:\\"should NOT have additional properties\\"};e===null?e=[d]:e.push(d),r++}if(o.foo!==void 0&&typeof o.foo!=\\"string\\"){var l={keyword:\\"type\\",dataPath:a+\\"/foo\\",schemaPath:\\"#/properties/foo/type\\",params:{type:\\"string\\"},message:\\"should be string\\"};e===null?e=[l]:e.push(l),r++}}else{var c={keyword:\\"type\\",dataPath:a,schemaPath:\\"#/type\\",params:{type:\\"object\\"},message:\\"should be object\\"};e===null?e=[c]:e.push(c),r++}return i.errors=e,r===0}}(p),p.exports}var u=P();u({foo:12});})();
1515
"
1616
`;
17+
18+
exports[`loads with doNotLoadConfig 1`] = `
19+
"(()=>{var v=(typeof window==\\"undefined\\"?globalThis:window)||{},i=v._appConfig;if(typeof i==\\"undefined\\")throw new Error(\\"Config is not loaded in _appConfig\\");function m(){let s={};return function(p){\\"use strict\\";p.exports=n,p.exports.default=n;var P={type:\\"object\\",additionalProperties:!1,properties:{foo:{type:\\"string\\"}},$schema:\\"http://json-schema.org/draft-07/schema#\\"};function n(o,t){\\"use strict\\";if(t)var r=t.dataPath,h=t.parentData,g=t.parentDataProperty,y=t.rootData;else var r=\\"\\",h=void 0,g=void 0,y=o;var e=null,a=0;if(o&&typeof o==\\"object\\"&&!Array.isArray(o)){for(var f in o)if(f!==\\"foo\\"){var d={keyword:\\"additionalProperties\\",dataPath:r,schemaPath:\\"#/additionalProperties\\",params:{additionalProperty:f},message:\\"should NOT have additional properties\\"};e===null?e=[d]:e.push(d),a++}if(o.foo!==void 0&&typeof o.foo!=\\"string\\"){var l={keyword:\\"type\\",dataPath:r+\\"/foo\\",schemaPath:\\"#/properties/foo/type\\",params:{type:\\"string\\"},message:\\"should be string\\"};e===null?e=[l]:e.push(l),a++}}else{var u={keyword:\\"type\\",dataPath:r,schemaPath:\\"#/type\\",params:{type:\\"object\\"},message:\\"should be object\\"};e===null?e=[u]:e.push(u),a++}return n.errors=e,a===0}}(s),s.exports}var c=m();c(i);})();
20+
"
21+
`;

app-config-esbuild/src/index.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,33 @@ it('loads currentEnvironment', () =>
121121
expect(res.outputFiles[0].text).toMatchSnapshot();
122122
},
123123
));
124+
125+
it('loads with doNotLoadConfig', () =>
126+
withTempFiles(
127+
{
128+
'.app-config.schema.yml': `
129+
type: object
130+
additionalProperties: false
131+
properties:
132+
foo: { type: string }
133+
`,
134+
'a.js': `
135+
import { config, validateConfig } from '@app-config/main';
136+
137+
validateConfig(config);
138+
`,
139+
},
140+
async (inDir) => {
141+
const res = await build({
142+
entryPoints: [inDir('a.js')],
143+
plugins: [
144+
createPlugin({ schemaLoadingOptions: { directory: inDir('.') }, doNotLoadConfig: true }),
145+
],
146+
bundle: true,
147+
minify: true,
148+
write: false,
149+
});
150+
151+
expect(res.outputFiles[0].text).toMatchSnapshot();
152+
},
153+
));

app-config-utils/src/__snapshots__/index.test.ts.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ exports[`generateModuleText creates config module 1`] = `
1313
"
1414
`;
1515

16+
exports[`generateModuleText creates config module with doNotLoadConfig 1`] = `
17+
"
18+
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {};
19+
20+
const config = globalNamespace._appConfig;
21+
22+
if (typeof config === 'undefined') {
23+
throw new Error('Config is not loaded in _appConfig');
24+
}
25+
26+
export { config };
27+
export default config;
28+
29+
export function currentEnvironment() {
30+
return globalNamespace._appConfigEnvironment || \\"test\\";
31+
}
32+
"
33+
`;
34+
1635
exports[`generateModuleText creates config module with esm validation function 1`] = `
1736
"
1837
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {};

app-config-utils/src/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ describe('generateModuleText', () => {
5959
).toMatchSnapshot();
6060
});
6161

62+
it('creates config module with doNotLoadConfig', () => {
63+
expect(
64+
generateModuleText('no-config', {
65+
environment: 'test',
66+
useGlobalNamespace: true,
67+
esmValidationCode: false,
68+
validationFunctionCode: undefined,
69+
}),
70+
).toMatchSnapshot();
71+
});
72+
6273
it('creates config module with validation function', () => {
6374
expect(
6475
generateModuleText(

0 commit comments

Comments
 (0)