Fix Mocha boot crash (test __dirname) and load the new avatar/import-export server files
Two build/load fixes surfaced by running the full test suite: - server/imports.js: import the new server-only files so they actually load. In mainModule mode a file not imported here never loads, so Accounts.onLogin avatar localization (server/avatarLocalizationOnLogin.js) and the imported-user reconciliation Meteor methods (server/importedUserReconciliation.js) would silently never register. - Test __dirname collision: 'meteor test' crashed at boot with 'Identifier __dirname has already been declared'. The client test index (client/lib/tests/index.js) loads boardTriggersClass.tests.js, which referenced the bare __dirname global; under meteor test that makes Meteor inject a colliding with its CommonJS wrapper's, aborting the whole server bundle (the same failure already fixed once in dependencies.openapi.tests.js — this was the next file to trip it). Replace __dirname with a process.cwd()/PWD walk-up in boardTriggersClass.tests.js, and defensively in the node-run tests/rtl.test.js, tests/stickers.test.js and tests/stickers.packs.test.js too. Thanks to xet7.
This commit is contained in:
1 parent
bb7fe88bd5
commit
cf217784d1
5 files changed
+85
-10
No files matched your search
@@ -17,7 +17,25 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { expect } = require('chai');
|
||||
|
||||
const repoRoot = path.resolve(__dirname, '..', '..', '..');
|
||||
// Find the repo root by walking up from process.cwd()/PWD, NOT from the bare `__dirname`
|
||||
// global: under `meteor test` referencing `__dirname` makes Meteor inject a
|
||||
// `const __dirname` that collides with the one its CommonJS module wrapper already
|
||||
// provides, crashing the whole server bundle at boot with "Identifier '__dirname' has
|
||||
// already been declared" (same fix as server/lib/tests/dependencies.openapi.tests.js).
|
||||
function findRepoRoot(marker) {
|
||||
const seeds = [process.cwd(), process.env.PWD, process.env.OLDPWD].filter(Boolean);
|
||||
for (const seed of seeds) {
|
||||
let dir = seed;
|
||||
for (let i = 0; i < 12; i += 1) {
|
||||
try { fs.accessSync(path.join(dir, marker)); return dir; } catch (e) { /* walk up */ }
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
return process.cwd();
|
||||
}
|
||||
const repoRoot = findRepoRoot(path.join('client', 'components', 'rules', 'triggers', 'boardTriggers.jade'));
|
||||
const jadePath = path.join(
|
||||
repoRoot,
|
||||
'client',
|
||||
|
||||
@@ -291,6 +291,15 @@ import '/server/permissions/unsavedEdits';
|
||||
import '/server/permissions/userPositionHistory';
|
||||
import '/server/permissions/users';
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// External-avatar localization + imported-user reconciliation
|
||||
// ----------------------------------------------------------------------------
|
||||
// Register the Accounts.onLogin avatar-localization trigger and the imported-user
|
||||
// reconciliation Meteor methods. In mainModule mode a file that is not imported here is
|
||||
// never loaded, so its hooks/methods would silently never register.
|
||||
import '/server/avatarLocalizationOnLogin';
|
||||
import '/server/importedUserReconciliation';
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 17. Sandstorm integration
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
+19
-1
@@ -25,7 +25,25 @@ const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const repoRoot = path.resolve(__dirname, '..');
|
||||
// Find the repo root by walking up from process.cwd()/PWD, NOT from the bare `__dirname`
|
||||
// global: this file is also loaded by `meteor test`, where referencing `__dirname` makes
|
||||
// Meteor inject a `const __dirname` that collides with the one its CommonJS module wrapper
|
||||
// already provides, crashing the whole server bundle at boot with "Identifier '__dirname'
|
||||
// has already been declared" (same fix as server/lib/tests/dependencies.openapi.tests.js).
|
||||
function findRepoRoot(marker) {
|
||||
const seeds = [process.cwd(), process.env.PWD, process.env.OLDPWD].filter(Boolean);
|
||||
for (const seed of seeds) {
|
||||
let dir = seed;
|
||||
for (let i = 0; i < 12; i += 1) {
|
||||
try { fs.accessSync(path.join(dir, marker)); return dir; } catch (e) { /* walk up */ }
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
return process.cwd();
|
||||
}
|
||||
const repoRoot = findRepoRoot('imports/i18n/languages.js');
|
||||
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
|
||||
|
||||
// --- Parse the rtl flags straight out of languages.js -----------------------
|
||||
|
||||
@@ -11,10 +11,25 @@ const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const src = fs.readFileSync(
|
||||
path.join(__dirname, '..', 'models', 'metadata', 'stickers.js'),
|
||||
'utf8',
|
||||
);
|
||||
// Locate the source via a process.cwd()/PWD walk-up, NOT the bare `__dirname` global:
|
||||
// under `meteor test` referencing `__dirname` makes Meteor inject a `const __dirname`
|
||||
// that collides with the CommonJS module wrapper's, crashing the server bundle at boot
|
||||
// with "Identifier '__dirname' has already been declared".
|
||||
const STICKERS_REL = path.join('models', 'metadata', 'stickers.js');
|
||||
function findRepoRoot(marker) {
|
||||
const seeds = [process.cwd(), process.env.PWD, process.env.OLDPWD].filter(Boolean);
|
||||
for (const seed of seeds) {
|
||||
let dir = seed;
|
||||
for (let i = 0; i < 12; i += 1) {
|
||||
try { fs.accessSync(path.join(dir, marker)); return dir; } catch (e) { /* walk up */ }
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
return process.cwd();
|
||||
}
|
||||
const src = fs.readFileSync(path.join(findRepoRoot(STICKERS_REL), STICKERS_REL), 'utf8');
|
||||
|
||||
// --- parse the real tables from source ------------------------------------
|
||||
function parseExactMap(name) {
|
||||
|
||||
+19
-4
@@ -11,10 +11,25 @@ const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const src = fs.readFileSync(
|
||||
path.join(__dirname, '..', 'models', 'metadata', 'stickers.js'),
|
||||
'utf8',
|
||||
);
|
||||
// Locate the source via a process.cwd()/PWD walk-up, NOT the bare `__dirname` global:
|
||||
// under `meteor test` referencing `__dirname` makes Meteor inject a `const __dirname`
|
||||
// that collides with the CommonJS module wrapper's, crashing the server bundle at boot
|
||||
// with "Identifier '__dirname' has already been declared".
|
||||
const STICKERS_REL = path.join('models', 'metadata', 'stickers.js');
|
||||
function findRepoRoot(marker) {
|
||||
const seeds = [process.cwd(), process.env.PWD, process.env.OLDPWD].filter(Boolean);
|
||||
for (const seed of seeds) {
|
||||
let dir = seed;
|
||||
for (let i = 0; i < 12; i += 1) {
|
||||
try { fs.accessSync(path.join(dir, marker)); return dir; } catch (e) { /* walk up */ }
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
return process.cwd();
|
||||
}
|
||||
const src = fs.readFileSync(path.join(findRepoRoot(STICKERS_REL), STICKERS_REL), 'utf8');
|
||||
|
||||
function parseArray(name) {
|
||||
const m = src.match(new RegExp(`${name} = \\[([\\s\\S]*?)\\]`));
|
||||
|
||||
Reference in new issue
Block a user