Files
cocos4/tests/general/global-variable-cc.test.ts
T
Yun Hsiao Wu dfc3d141f2 GFX Descriptor Set (#7101)
* gfx: descriptor sets

* gfx: descriptor set, singular

* better structure

* adapt upper layers: first pass

finally all compiler errors cleared.

OKAY IT'S HAPPENING EVERYBODY STAY THE ****ING CALM

* adapt upper layers: second pass

THERE AND BACK AGAIN

* unified light pass & shadow shader

* gfx: descriptor set & pipeline layout

* light pass: better structure

* light pass: dynamic uniform

* even more type checking for memory pools

* Fix particleSystem and lineComponent.

* delete comment

* guard pool init param

* Fix trail module error.

* delete space

* light pass: instancing & batching support

* don't polyfill gfx stuff inside EffectAsset

* better light pass structure

* fix spot light culling

Co-authored-by: caryliu <caryliu1999@gmail.com>
2020-08-13 18:21:15 +08:00

62 lines
2.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-require-imports */
import fs from 'fs-extra';
import ps from 'path';
async function summarizeFilesInDirectory (directory: string) {
return (await fs.readdir(directory)).map((file) => ps.join(directory, file));
}
declare global {
const cc: object;
const _cc: object;
}
test('global variables are sealed', async () => {
const files = await summarizeFilesInDirectory(ps.join(__dirname, '..', '..', 'exports'));
for (const file of files) {
require(file);
}
const globalVariables: string[] = [];
const visited: Set<object> = new Set();
const getMembersRecursive = (object: {}, prefix: string) => {
const memberNames = Object.getOwnPropertyNames(object);
for (const memberName of memberNames) {
const member = object[memberName];
if (visited.has(member)) {
continue;
} else {
visited.add(member);
}
const path = `${prefix}.${memberName}`;
globalVariables.push(path);
// TODO: Recursive
// if (member === null) {
// console.warn(`${path} is \`null\`, is it intended?`);
// }
// else if (typeof member === 'object' && member.constructor === Object) {
// getMembersRecursive(member, path);
// }
}
};
// Global variable `cc`
getMembersRecursive(cc, 'cc');
const sealedGlobalVariablesFile = ps.join(__dirname, 'sealed-global-variables.json');
const output = false;
if (output) {
await fs.writeFile(sealedGlobalVariablesFile, JSON.stringify({
thisFile: {
stamp: new Date().toISOString(),
},
variables: globalVariables.sort(),
}, undefined, 4));
} else {
const sealedGlobalVariables = (await fs.readJson(sealedGlobalVariablesFile)).variables as string[];
const difference = globalVariables.filter((v) => !sealedGlobalVariables.includes(v));
expect(difference).toEqual([]);
}
}, 30000);