Skip to content

Commit

Permalink
Allow for bootstrap and custom deps js files for tests.
Browse files Browse the repository at this point in the history
RELNOTES: none

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168722489
  • Loading branch information
shicks committed Sep 17, 2017
1 parent 19eb0cd commit 0f976fd
Show file tree
Hide file tree
Showing 617 changed files with 1,469 additions and 5,307 deletions.
Expand Up @@ -200,32 +200,48 @@ function maybeGenerateHtmlForFile(filename, args) {
const newJS = `goog.require('${provide[1]}');`;
const title = `Closure Unit Tests - ${provide[1]}`;

const testDomFilename = filename.replace('_test.js', '_test_dom.html');
const baseFileName = filename.replace('_test.js', '');
const testDomFilename = baseFileName + '_test_dom.html';
const testDom = fs.existsSync(testDomFilename) ?
fs.readFileSync(testDomFilename, 'utf8') :
'';

const testBootstrapFilename = baseFileName + '_test_bootstrap.js';
const pathToBootstrap = fs.existsSync(testBootstrapFilename) ?
path.basename(testBootstrapFilename) :
'';

const testDepsFilename = baseFileName + '_test_deps.js';
const pathToDeps =
fs.existsSync(testDepsFilename) ? path.basename(testDepsFilename) : '';

const pathToBase = path.relative(path.dirname(htmlFilename), args.basePath);

const html = createHtml(title, newJS, testDom, pathToBase);
const html = createHtml(
title, pathToBootstrap, pathToDeps, newJS, testDom, pathToBase);
fs.writeFileSync(htmlFilename, html);
}

/**
* @param {string} title Title of the test.
* @param {string} pathToBootstrap Path to a bootstrap javascript file to run
* first, if any. Generally this file will contain closure defines.
* @param {string} pathToDeps Bath to a custom deps file, if any.
* @param {string} js Script content of the test.
* @param {string} testDom Any test DOM related to the test or the empty string
* if none.
* @param {string} pathToBase Path to the base.js file.
* @return {string} The text content of the test HTML file.
*/
function createHtml(title, js, testDom, pathToBase) {
function createHtml(
title, pathToBootstrap, pathToDeps, js, testDom, pathToBase) {
// Use parse5 to parse and reserialize the test dom. This generates any
// optional tags (html, body, head) if missing. Meaning test doms can specify
// these tags, if needed.
const parser = new Parser();
const serializer = new Serializer();
return serializer.serialize(parser.parse(
`<!DOCTYPE html>
`<!DOCTYPE html>
<!-- DO NOT EDIT. This file auto-generated by generate_closure_unit_tests.js -->
<!--
Copyright 2017 The Closure Library Authors. All Rights Reserved.
Expand All @@ -234,7 +250,9 @@ Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<meta charset="UTF-8" />
${pathToBootstrap ? `<script src=${pathToBootstrap}></script>` : ''}
<script src="${pathToBase}"></script>
${pathToDeps ? `<script src=${pathToDeps}></script>` : ''}
<script>${js}</script>
<title>${title}</title>` +
testDom));
Expand Down
11 changes: 3 additions & 8 deletions closure/goog/a11y/aria/announcer_test.html
Expand Up @@ -4,13 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../../base.js"></script>
<script>goog.require('goog.a11y.aria.AnnouncerTest');</script>
<title>Closure Unit Tests - goog.a11y.aria.AnnouncerTest</title><!--
Copyright 2017 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
</head><body><div id="sandbox">
</div></body></html>
<script>goog.require('goog.a11y.aria.AnnouncerTest');</script>
<title>Closure Unit Tests - goog.a11y.aria.AnnouncerTest</title></head><body></body></html>
11 changes: 3 additions & 8 deletions closure/goog/a11y/aria/aria_test.html
Expand Up @@ -4,13 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../../base.js"></script>
<script>goog.require('goog.a11y.ariaTest');</script>
<title>Closure Unit Tests - goog.a11y.ariaTest</title><!--
Copyright 2017 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
</head><body><div id="sandbox">
</div></body></html>
<script>goog.require('goog.a11y.ariaTest');</script>
<title>Closure Unit Tests - goog.a11y.ariaTest</title></head><body></body></html>
11 changes: 3 additions & 8 deletions closure/goog/array/array_test.html
Expand Up @@ -4,13 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>
<script>goog.require('goog.arrayTest');</script>
<title>Closure Unit Tests - goog.arrayTest</title><!--
Copyright 2017 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
</head><body><div class="foo">
</div></body></html>
<script>goog.require('goog.arrayTest');</script>
<title>Closure Unit Tests - goog.arrayTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/asserts/asserts_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.assertsTest');</script>
<title>Closure Unit Tests - goog.assertsTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/animationdelay_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.AnimationDelayTest');</script>
<title>Closure Unit Tests - goog.async.AnimationDelayTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/conditionaldelay_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.ConditionalDelayTest');</script>
<title>Closure Unit Tests - goog.async.ConditionalDelayTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/debouncer_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.DebouncerTest');</script>
<title>Closure Unit Tests - goog.async.DebouncerTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/delay_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.DelayTest');</script>
<title>Closure Unit Tests - goog.async.DelayTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/freelist_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.FreeListTest');</script>
<title>Closure Unit Tests - goog.async.FreeListTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/nexttick_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.nextTickTest');</script>
<title>Closure Unit Tests - goog.async.nextTickTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/run_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.runTest');</script>
<title>Closure Unit Tests - goog.async.runTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/throttle_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.ThrottleTest');</script>
<title>Closure Unit Tests - goog.async.ThrottleTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/async/workqueue_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.async.WorkQueueTest');</script>
<title>Closure Unit Tests - goog.async.WorkQueueTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/base_module_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="base.js"></script>

<script>goog.require('goog.baseModuleTest');</script>
<title>Closure Unit Tests - goog.baseModuleTest</title></head><body></body></html>
25 changes: 3 additions & 22 deletions closure/goog/base_test.html
Expand Up @@ -4,27 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">
<script src="base.js"></script>
<script>goog.require('goog.baseTest');</script>
<title>Closure Unit Tests - goog.baseTest</title><!--
Copyright 2017 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<script>
var CLOSURE_DEFINES = {
'SOME_DEFINE': 456,
'ns.SOME_DEFINE': 456
};
</script>

</head><body><div id="elem">
<span>One</span>
<span id="text">Two</span>
<span>Three</span>
</div>
<script src="base.js"></script>

<iframe name="f1" id="f1" src=""></iframe>
<iframe name="f2" id="f2" src=""></iframe>
</body></html>
<script>goog.require('goog.baseTest');</script>
<title>Closure Unit Tests - goog.baseTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/color/alpha_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.color.alphaTest');</script>
<title>Closure Unit Tests - goog.color.alphaTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/color/color_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.colorTest');</script>
<title>Closure Unit Tests - goog.colorTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/aes_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.AesTest');</script>
<title>Closure Unit Tests - goog.crypt.AesTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/arc4_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.Arc4Test');</script>
<title>Closure Unit Tests - goog.crypt.Arc4Test</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/base64_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.base64Test');</script>
<title>Closure Unit Tests - goog.crypt.base64Test</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/basen_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.baseNTest');</script>
<title>Closure Unit Tests - goog.crypt.baseNTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/blobhasher_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.BlobHasherTest');</script>
<title>Closure Unit Tests - goog.crypt.BlobHasherTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/cbc_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.CbcTest');</script>
<title>Closure Unit Tests - goog.crypt.CbcTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/crypt_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.cryptTest');</script>
<title>Closure Unit Tests - goog.cryptTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/ctr_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.CtrTest');</script>
<title>Closure Unit Tests - goog.crypt.CtrTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/hash32_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.hash32Test');</script>
<title>Closure Unit Tests - goog.crypt.hash32Test</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/hmac_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.HmacTest');</script>
<title>Closure Unit Tests - goog.crypt.HmacTest</title></head><body></body></html>
2 changes: 2 additions & 0 deletions closure/goog/crypt/md5_test.html
Expand Up @@ -4,6 +4,8 @@
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.crypt.Md5Test');</script>
<title>Closure Unit Tests - goog.crypt.Md5Test</title></head><body></body></html>

0 comments on commit 0f976fd

Please sign in to comment.