|
| 1 | +import test from "ava"; |
| 2 | +import Eleventy from "../src/Eleventy.js"; |
| 3 | + |
| 4 | +test("addBundle", async (t) => { |
| 5 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 6 | + config: eleventyConfig => { |
| 7 | + eleventyConfig.addPlugin(() => { |
| 8 | + eleventyConfig.addBundle("css") |
| 9 | + }); |
| 10 | + eleventyConfig.addTemplate("index.njk", "{% css %}/* Hi */{% endcss %}<style>{% getBundle 'css' %}</style>"); |
| 11 | + } |
| 12 | + }); |
| 13 | + |
| 14 | + let results = await elev.toJSON(); |
| 15 | + t.is(results[0].content, `<style>/* Hi */</style>`); |
| 16 | +}); |
| 17 | + |
| 18 | +test("addBundle (empty css)", async (t) => { |
| 19 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 20 | + config: eleventyConfig => { |
| 21 | + eleventyConfig.addPlugin(() => { |
| 22 | + eleventyConfig.addBundle("css"); |
| 23 | + }); |
| 24 | + |
| 25 | + eleventyConfig.addTemplate("index.njk", "Hi<style>{% getBundle 'css' %}</style>"); |
| 26 | + } |
| 27 | + }); |
| 28 | + |
| 29 | + let results = await elev.toJSON(); |
| 30 | + t.is(results[0].content, `Hi`); |
| 31 | +}); |
| 32 | + |
| 33 | +test("addBundle (empty js)", async (t) => { |
| 34 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 35 | + config: eleventyConfig => { |
| 36 | + eleventyConfig.addPlugin(() => { |
| 37 | + eleventyConfig.addBundle("js"); |
| 38 | + }); |
| 39 | + |
| 40 | + eleventyConfig.addTemplate("index.njk", "Hi<script>{% getBundle 'js' %}</script>"); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + let results = await elev.toJSON(); |
| 45 | + t.is(results[0].content, `Hi`); |
| 46 | +}); |
| 47 | + |
| 48 | +test("Empty script node is removed (not using bundle)", async (t) => { |
| 49 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 50 | + config: eleventyConfig => { |
| 51 | + eleventyConfig.addPlugin(() => { |
| 52 | + eleventyConfig.addBundle("js"); |
| 53 | + }); |
| 54 | + |
| 55 | + eleventyConfig.addTemplate("index.njk", "Hi<script></script>"); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | + let results = await elev.toJSON(); |
| 60 | + t.is(results[0].content, `Hi`); |
| 61 | +}); |
| 62 | + |
| 63 | + |
| 64 | +test("Empty style node is removed (not using bundle)", async (t) => { |
| 65 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 66 | + config: eleventyConfig => { |
| 67 | + eleventyConfig.addPlugin(() => { |
| 68 | + eleventyConfig.addBundle("css"); |
| 69 | + }); |
| 70 | + |
| 71 | + eleventyConfig.addTemplate("index.njk", "Hi<style></style>"); |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + let results = await elev.toJSON(); |
| 76 | + t.is(results[0].content, `Hi`); |
| 77 | +}); |
| 78 | + |
| 79 | +test("Empty link node is removed (not using bundle)", async (t) => { |
| 80 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 81 | + config: eleventyConfig => { |
| 82 | + eleventyConfig.addPlugin(() => { |
| 83 | + eleventyConfig.addBundle("css"); |
| 84 | + }); |
| 85 | + |
| 86 | + eleventyConfig.addTemplate("index.njk", "Hi<link rel='stylesheet' href=''>"); |
| 87 | + } |
| 88 | + }); |
| 89 | + |
| 90 | + let results = await elev.toJSON(); |
| 91 | + t.is(results[0].content, `Hi`); |
| 92 | +}); |
| 93 | + |
| 94 | +test("Empty link node is removed (no href attribute at all, not using bundle)", async (t) => { |
| 95 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 96 | + config: eleventyConfig => { |
| 97 | + eleventyConfig.addPlugin(() => { |
| 98 | + eleventyConfig.addBundle("css"); |
| 99 | + }); |
| 100 | + |
| 101 | + eleventyConfig.addTemplate("index.njk", "Hi<link rel='stylesheet'>"); |
| 102 | + } |
| 103 | + }); |
| 104 | + |
| 105 | + let results = await elev.toJSON(); |
| 106 | + t.is(results[0].content, `Hi`); |
| 107 | +}); |
| 108 | + |
| 109 | +test("Empty link node is kept (no rel attribute, not using bundle)", async (t) => { |
| 110 | + let elev = new Eleventy("./test/stubs-virtual/", undefined, { |
| 111 | + config: eleventyConfig => { |
| 112 | + eleventyConfig.addPlugin(() => { |
| 113 | + eleventyConfig.addBundle("css"); |
| 114 | + }); |
| 115 | + |
| 116 | + eleventyConfig.addTemplate("index.njk", "Hi<link>"); |
| 117 | + } |
| 118 | + }); |
| 119 | + |
| 120 | + let results = await elev.toJSON(); |
| 121 | + t.is(results[0].content, `Hi<link>`); |
| 122 | +}); |
0 commit comments