forked from 11ty/eleventy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for bundle plugin transform removing empty nodes (need htmlTransf…
…ormer earlier) 11ty/eleventy-plugin-bundle#8
- Loading branch information
Showing
2 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import test from "ava"; | ||
import Eleventy from "../src/Eleventy.js"; | ||
|
||
test("addBundle", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("css") | ||
}); | ||
eleventyConfig.addTemplate("index.njk", "{% css %}/* Hi */{% endcss %}<style>{% getBundle 'css' %}</style>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `<style>/* Hi */</style>`); | ||
}); | ||
|
||
test("addBundle (empty css)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("css"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<style>{% getBundle 'css' %}</style>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi`); | ||
}); | ||
|
||
test("addBundle (empty js)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("js"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<script>{% getBundle 'js' %}</script>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi`); | ||
}); | ||
|
||
test("Empty script node is removed (not using bundle)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("js"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<script></script>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi`); | ||
}); | ||
|
||
|
||
test("Empty style node is removed (not using bundle)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("css"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<style></style>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi`); | ||
}); | ||
|
||
test("Empty link node is removed (not using bundle)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("css"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<link rel='stylesheet' href=''>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi`); | ||
}); | ||
|
||
test("Empty link node is removed (no href attribute at all, not using bundle)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("css"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<link rel='stylesheet'>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi`); | ||
}); | ||
|
||
test("Empty link node is kept (no rel attribute, not using bundle)", async (t) => { | ||
let elev = new Eleventy("./test/stubs-virtual/", undefined, { | ||
config: eleventyConfig => { | ||
eleventyConfig.addPlugin(() => { | ||
eleventyConfig.addBundle("css"); | ||
}); | ||
|
||
eleventyConfig.addTemplate("index.njk", "Hi<link>"); | ||
} | ||
}); | ||
|
||
let results = await elev.toJSON(); | ||
t.is(results[0].content, `Hi<link>`); | ||
}); |