Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner committed Nov 20, 2024
1 parent 7a33ad2 commit 2f81d9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
22 changes: 16 additions & 6 deletions lib/utils/find-and-replace-in-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
const fs = require('fs-extra');
const path = require('path');

function processFile(filePath, addonDocsRootURL, encodedVersion) {
const contents = fs.readFileSync(filePath, 'utf-8');

contents
function replaceAddonDocsRootURL(contents, addonDocsRootURL, encodedVersion) {
return contents
.replace('%2FADDON_DOCS_ROOT_URL%2F', encodeURIComponent(addonDocsRootURL))
.replace(/\/?ADDON_DOCS_ROOT_URL\/?/g, addonDocsRootURL)
.replace(/%22ADDON_DOCS_DEPLOY_VERSION%22/g, encodedVersion);
}

function processFile(filePath, addonDocsRootURL, encodedVersion) {
const contents = fs.readFileSync(filePath, 'utf-8');

// Write the updated content to the file
fs.writeFileSync(filePath, contents);
fs.writeFileSync(
filePath,
replaceAddonDocsRootURL(contents, addonDocsRootURL, encodedVersion),
);
}

module.exports = function findAndReplaceInDirectory(
function findAndReplaceInDirectory(
directory,
addonDocsRootURL,
encodedVersion,
Expand All @@ -40,4 +45,9 @@ module.exports = function findAndReplaceInDirectory(
}
});
});
}

module.exports = {
findAndReplaceInDirectory,
replaceAddonDocsRootURL,
};
16 changes: 9 additions & 7 deletions tests-node/unit/deploy/plugin-test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict';

const assert = require('chai').assert;
const AddonDocsDeployPlugin = require('../../../lib/deploy/plugin');
const {
replaceAddonDocsRootURL,
} = require('../../../lib/utils/find-and-replace-in-directory');

describe('`deploy` | plugin test', function () {
beforeEach(function () {
this.pluginInstance = new AddonDocsDeployPlugin();
});

it.skip('_macroReplaceIndexContent', function () {
it('replaceAddonDocsRootURL', function () {
const contents = `
<!DOCTYPE html>
<html>
<head>
<meta name="dummy/config/environment" content="%7B%22rootURL%22%3A%22%2FADDON_DOCS_ROOT_URL%2F%22%7D" />
</head>
<body>
<script src="ADDON_DOCS_ROOT_URL/assets/chunk.805.d0514e7e9edb751c6623.js"></script>
<script src="ADDON_DOCS_ROOT_URL/assets/chunk.524.385868f2db0b958b5ced.js"></script>
<script src="/ADDON_DOCS_ROOT_URL/assets/vendor.js"></script>
<script src="/ADDON_DOCS_ROOT_URL/assets/dummy.js"></script>
</body>
Expand All @@ -31,7 +31,7 @@ describe('`deploy` | plugin test', function () {
}),
);
const addonDocsRootURL = '/my-addon/versions/master/';
const actual = this.pluginInstance._macroReplaceIndexContent(
const actual = replaceAddonDocsRootURL(
contents,
addonDocsRootURL,
encodedVersion,
Expand All @@ -43,6 +43,8 @@ describe('`deploy` | plugin test', function () {
<meta name="dummy/config/environment" content="%7B%22rootURL%22%3A%22%2Fmy-addon%2Fversions%2Fmaster%2F%22%7D" />
</head>
<body>
<script src="/my-addon/versions/master/assets/chunk.805.d0514e7e9edb751c6623.js"></script>
<script src="/my-addon/versions/master/assets/chunk.524.385868f2db0b958b5ced.js"></script>
<script src="/my-addon/versions/master/assets/vendor.js"></script>
<script src="/my-addon/versions/master/assets/dummy.js"></script>
</body>
Expand Down

0 comments on commit 2f81d9b

Please sign in to comment.