Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix(dev-holocron-cdn): allow no local module map (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAdshead committed Feb 19, 2021
1 parent b73e30a commit 58e1f7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 23 additions & 1 deletion __tests__/server/devHolocronCDN.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import path from 'path';

import fs from 'fs';
import findUp from 'find-up';
import request from 'supertest';

Expand All @@ -36,6 +36,7 @@ describe('devHolocronCDN', () => {

beforeEach(() => {
jest.resetModules();
jest.spyOn(fs, 'existsSync').mockImplementation(() => true);
jest.mock('cors', () => jest.fn(() => (req, res, next) => next()));
jest.mock('@americanexpress/one-app-dev-cdn', () => jest.fn(() => (req, res, next) => next()));
});
Expand Down Expand Up @@ -80,6 +81,27 @@ describe('devHolocronCDN', () => {
});
});
});

it('does not require useLocalModules when no static module-map', () => {
fs.existsSync.mockImplementationOnce(() => false);
const moduleMapUrl = 'https://example.com/module-map.json';
process.argv = [
'',
'',
'--module-map-url',
moduleMapUrl,
];

load();
return findUp('package.json')
.then((filepath) => {
expect(oneAppDevCdn).toHaveBeenCalledWith({
localDevPublicPath: path.join(path.dirname(filepath), 'static'),
remoteModuleMapUrl: moduleMapUrl,
useLocalModules: false,
});
});
});
});

describe('routing', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/server/devHolocronCDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true }] */

import path from 'path';

import fs from 'fs';
import express from 'express';
import cors from 'cors';
import { argv } from 'yargs';
import oneAppDevCdn from '@americanexpress/one-app-dev-cdn';

const hasLocalModuleMap = () => fs.existsSync(path.join(process.cwd(), 'static', 'module-map.json'));

const app = express();

app.use(cors());
app.use('/static', oneAppDevCdn({
localDevPublicPath: path.join(__dirname, '../../static'),
remoteModuleMapUrl: argv.moduleMapUrl,
useLocalModules: true,
useLocalModules: hasLocalModuleMap(),
appPort: process.env.HTTP_PORT,
useHost: argv.useHost,
}));
Expand Down

0 comments on commit 58e1f7d

Please sign in to comment.