DEV: Compile plugin tests using ember-cli (#18074)
For now, `EMBER_CLI_PLUGIN_ASSETS` can be set to 0 to restore the old behavior. This option will be removed very soon.
This commit is contained in:
parent
e9dac86cc0
commit
e141208605
|
@ -78,12 +78,20 @@ module.exports = {
|
||||||
return pluginDirectories.map((directory) => {
|
return pluginDirectories.map((directory) => {
|
||||||
const name = directory.name;
|
const name = directory.name;
|
||||||
const jsDirectory = path.resolve(root, name, "assets/javascripts");
|
const jsDirectory = path.resolve(root, name, "assets/javascripts");
|
||||||
|
const testDirectory = path.resolve(root, name, "test/javascripts");
|
||||||
const hasJs = fs.existsSync(jsDirectory);
|
const hasJs = fs.existsSync(jsDirectory);
|
||||||
return { name, jsDirectory, hasJs };
|
const hasTests = fs.existsSync(testDirectory);
|
||||||
|
return { name, jsDirectory, testDirectory, hasJs, hasTests };
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
generatePluginsTree() {
|
generatePluginsTree() {
|
||||||
|
const appTree = this._generatePluginAppTree();
|
||||||
|
const testTree = this._generatePluginTestTree();
|
||||||
|
return mergeTrees([appTree, testTree]);
|
||||||
|
},
|
||||||
|
|
||||||
|
_generatePluginAppTree() {
|
||||||
const trees = this.pluginInfos()
|
const trees = this.pluginInfos()
|
||||||
.filter((p) => p.hasJs)
|
.filter((p) => p.hasJs)
|
||||||
.map(({ name, jsDirectory }) => {
|
.map(({ name, jsDirectory }) => {
|
||||||
|
@ -101,6 +109,26 @@ module.exports = {
|
||||||
return concat(mergeTrees([tree]), {
|
return concat(mergeTrees([tree]), {
|
||||||
inputFiles: ["**/*.js"],
|
inputFiles: ["**/*.js"],
|
||||||
outputFile: `assets/plugins/${name}.js`,
|
outputFile: `assets/plugins/${name}.js`,
|
||||||
|
allowNone: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return mergeTrees(trees);
|
||||||
|
},
|
||||||
|
|
||||||
|
_generatePluginTestTree() {
|
||||||
|
const trees = this.pluginInfos()
|
||||||
|
.filter((p) => p.hasTests)
|
||||||
|
.map(({ name, testDirectory }) => {
|
||||||
|
let tree = new WatchedDir(testDirectory);
|
||||||
|
|
||||||
|
tree = fixLegacyExtensions(tree);
|
||||||
|
tree = namespaceModules(tree, name);
|
||||||
|
tree = this.processedAddonJsFiles(tree);
|
||||||
|
|
||||||
|
return concat(mergeTrees([tree]), {
|
||||||
|
inputFiles: ["**/*.js"],
|
||||||
|
outputFile: `assets/plugins/test/${name}_tests.js`,
|
||||||
|
allowNone: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return mergeTrees(trees);
|
return mergeTrees(trees);
|
||||||
|
|
|
@ -411,7 +411,19 @@ module.exports = {
|
||||||
)
|
)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
} else if (shouldLoadPluginTestJs() && type === "test-plugin-tests-js") {
|
} else if (shouldLoadPluginTestJs() && type === "test-plugin-tests-js") {
|
||||||
return `<script id="plugin-test-script" src="${config.rootURL}assets/discourse/tests/plugin-tests.js" data-discourse-plugin="_all"></script>`;
|
if (process.env.EMBER_CLI_PLUGIN_ASSETS !== "0") {
|
||||||
|
return this.app.project
|
||||||
|
.findAddonByName("discourse-plugins")
|
||||||
|
.pluginInfos()
|
||||||
|
.filter(({ hasTests }) => hasTests)
|
||||||
|
.map(
|
||||||
|
({ name }) =>
|
||||||
|
`<script src="${config.rootURL}assets/plugins/test/${name}_tests.js" data-discourse-plugin="${name}"></script>`
|
||||||
|
)
|
||||||
|
.join("\n");
|
||||||
|
} else {
|
||||||
|
return `<script id="plugin-test-script" src="${config.rootURL}assets/discourse/tests/plugin-tests.js" data-discourse-plugin="_all"></script>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue