Skip to content

Commit

Permalink
content as data import map test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Oct 17, 2024
1 parent 750c607 commit 08bbaa1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/plugins/resource/plugin-content-as-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class ContentAsDataResource extends ResourceInterface {
let newBody = body;

if (contentAsData) {
newBody = mergeImportMap(body, importMap, polyfills.importMaps);
if (process.env.__GWD_COMMAND__ === 'develop') { // eslint-disable-line no-underscore-dangle
newBody = mergeImportMap(body, importMap, polyfills.importMaps);
}

newBody = newBody.replace('<head>', `
<head>
<script id="content-server">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Build Greenwood With: ', function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
runner = new Runner(true);
});

describe(LABEL, function() {
Expand Down Expand Up @@ -93,6 +93,18 @@ describe('Build Greenwood With: ', function() {
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, './index.html'));
});

describe('Data Client Import Map', () => {
let map;

before(function() {
map = dom.window.document.querySelectorAll('script[type="importmap"]');
});

it('should not have a <script> tag of type importmap', async () => {
expect(map.length).to.equal(0);
});
});

describe('navigation links from getContentByCollection', function() {
let navLinks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

import chai from 'chai';
import { JSDOM } from 'jsdom';
import path from 'path';
import { getSetupFiles, getOutputTeardownFiles } from '../../../../../test/utils.js';
import { Runner } from 'gallinago';
Expand Down Expand Up @@ -69,6 +70,29 @@ describe('Develop Greenwood With: ', function() {
});
});

describe('Data Client Import Map', () => {
let response;
let dom;

before(async function() {
response = await fetch(`${hostname}:${port}/`);
dom = new JSDOM(await response.text());
});

it('should have a <script> tag of type importmap', async () => {
const map = dom.window.document.querySelectorAll('script[type="importmap"]');

expect(map.length).to.equal(1);
});

it('should have the expected entry in the importmap', async () => {
const map = dom.window.document.querySelectorAll('script[type="importmap"]');
const contents = JSON.parse(map[0].textContent);

expect(contents.imports['@greenwood/cli/src/data/client.js']).to.equal('/node_modules/@greenwood/cli/src/data/client.js');
});
});

describe('Content Request Types', () => {
describe('Graph Request', () => {
let response;
Expand Down

0 comments on commit 08bbaa1

Please sign in to comment.