diff --git a/.gitignore b/.gitignore index 0410070..40b0228 100755 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ *.DS_Store # NPM -node_modules +/node_modules npm-debug.log # Build diff --git a/README.md b/README.md index 79b129d..b9f0097 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ module.exports = { moduleFileExtensions: defaults.moduleFileExtensions.concat("marko"), // preprocesses Marko files. transform: { "\\.marko$": "@marko/jest" }, - // transforms top level `.marko` files in the Marko package. - transformIgnorePatterns: ["node_modules/(?!(marko)/)"] + // transforms `.marko` files in node_modules as well + transformIgnorePatterns: ["node_modules/.*(? all.indexOf(name) === i) - .filter(name => - fs.existsSync(path.join(nodeModulesPath, name, "marko.json")) - ) - .map(escapeRegexp) - .concat("marko") - .join("|")})/)` - ] + // Here we whitelist all `.marko` files. + transformIgnorePatterns: ["node_modules/.*(? { document.body.innerHTML = ""; @@ -21,3 +22,11 @@ test("can be mocked", async () => { `"
Hello Mocked
"` ); }); + +test("transforms templates in node_modules", async () => { + const result = await Project.render({}); + result.appendTo(document.body).getComponent(); + expect(document.body.innerHTML).toMatchInlineSnapshot( + `"
Hello World
"` + ); +}); diff --git a/test/fixtures/project/index.marko b/test/fixtures/project/index.marko new file mode 100644 index 0000000..c3ba87d --- /dev/null +++ b/test/fixtures/project/index.marko @@ -0,0 +1,3 @@ + + Hello World + \ No newline at end of file diff --git a/test/fixtures/project/index.marko.d.ts b/test/fixtures/project/index.marko.d.ts new file mode 100644 index 0000000..0a3c1f1 --- /dev/null +++ b/test/fixtures/project/index.marko.d.ts @@ -0,0 +1,2 @@ +declare let x: any; +export = x; diff --git a/test/fixtures/project/node_modules/direct/index.marko b/test/fixtures/project/node_modules/direct/index.marko new file mode 100644 index 0000000..a381eb2 --- /dev/null +++ b/test/fixtures/project/node_modules/direct/index.marko @@ -0,0 +1,5 @@ + + + <${input.renderBody}/> + + \ No newline at end of file diff --git a/test/fixtures/project/node_modules/direct/marko.json b/test/fixtures/project/node_modules/direct/marko.json new file mode 100644 index 0000000..63ac777 --- /dev/null +++ b/test/fixtures/project/node_modules/direct/marko.json @@ -0,0 +1,5 @@ +{ + "": { + "template": "./index.marko" + } +} \ No newline at end of file diff --git a/test/fixtures/project/node_modules/direct/node_modules/indirect/index.marko b/test/fixtures/project/node_modules/direct/node_modules/indirect/index.marko new file mode 100644 index 0000000..f8886cf --- /dev/null +++ b/test/fixtures/project/node_modules/direct/node_modules/indirect/index.marko @@ -0,0 +1,3 @@ + + <${input.renderBody}/> + \ No newline at end of file diff --git a/test/fixtures/project/node_modules/direct/node_modules/indirect/marko.json b/test/fixtures/project/node_modules/direct/node_modules/indirect/marko.json new file mode 100644 index 0000000..0a42f7d --- /dev/null +++ b/test/fixtures/project/node_modules/direct/node_modules/indirect/marko.json @@ -0,0 +1,5 @@ +{ + "": { + "template": "./index.marko" + } +} \ No newline at end of file diff --git a/test/fixtures/project/node_modules/direct/node_modules/indirect/package.json b/test/fixtures/project/node_modules/direct/node_modules/indirect/package.json new file mode 100644 index 0000000..67dfab3 --- /dev/null +++ b/test/fixtures/project/node_modules/direct/node_modules/indirect/package.json @@ -0,0 +1,3 @@ +{ + "name": "direct" +} \ No newline at end of file diff --git a/test/fixtures/project/node_modules/direct/package.json b/test/fixtures/project/node_modules/direct/package.json new file mode 100644 index 0000000..4b09544 --- /dev/null +++ b/test/fixtures/project/node_modules/direct/package.json @@ -0,0 +1,6 @@ +{ + "name": "indirect", + "dependencies": { + "indirect": "*" + } +} \ No newline at end of file diff --git a/test/fixtures/project/package.json b/test/fixtures/project/package.json new file mode 100644 index 0000000..9cb1d13 --- /dev/null +++ b/test/fixtures/project/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "direct": "*" + } +} \ No newline at end of file diff --git a/test/server.test.ts b/test/server.test.ts index 93097e0..21bbfe6 100644 --- a/test/server.test.ts +++ b/test/server.test.ts @@ -1,5 +1,6 @@ import Example from "./fixtures/example.marko"; import Mockable from "./fixtures/mockable.marko"; +import Project from "./fixtures/project/index.marko"; test("server rendering", () => { expect(Example.renderSync({}).toString()).toMatchInlineSnapshot( @@ -13,3 +14,9 @@ test("can be mocked", async () => { `"
Hello Mocked
"` ); }); + +test("transforms templates in node_modules", () => { + expect(Project.renderSync({}).toString()).toMatchInlineSnapshot( + `"
Hello World
"` + ); +});