@atlassian/webresource-webpack-plugin 4.10.2-64a2ef2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +20 -0
- package/.eslintrc +72 -0
- package/.nvmrc +1 -0
- package/.prettierrc +6 -0
- package/CHANGELOG.md +318 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +13 -0
- package/README.md +709 -0
- package/RELEASE.md +17 -0
- package/package.json +118 -0
- package/src/AppResources.js +198 -0
- package/src/QUnitTestResources.js +88 -0
- package/src/WebpackHelpers.js +176 -0
- package/src/WebpackRuntimeHelpers.js +7 -0
- package/src/WrmPlugin.js +676 -0
- package/src/defaults/builtInProvidedDependencies.js +22 -0
- package/src/flattenReduce.js +1 -0
- package/src/helpers/options-parser.js +32 -0
- package/src/helpers/provided-dependencies.js +21 -0
- package/src/helpers/string.js +12 -0
- package/src/helpers/web-resource-entrypoints.js +66 -0
- package/src/helpers/web-resource-generator.js +138 -0
- package/src/helpers/web-resource-parser.js +44 -0
- package/src/helpers/xml.js +44 -0
- package/src/logger.js +28 -0
- package/src/mergeMaps.js +32 -0
- package/src/renderCondition.js +29 -0
- package/src/renderTransformation.js +44 -0
- package/src/settings/base-dependencies.js +42 -0
- package/src/shims/qunit-require-shim.js +19 -0
- package/src/types/typedefs.js +50 -0
- package/src/webpack-modules/EmptyExportsModule.js +26 -0
- package/src/webpack-modules/ProvidedExternalDependencyModule.js +30 -0
- package/src/webpack-modules/WrmDependencyModule.js +12 -0
- package/src/webpack-modules/WrmResourceModule.js +33 -0
- package/test/.eslintrc +11 -0
- package/test/unit/ProvidedExternalDependencyModule.test.js +63 -0
- package/test/unit/WebpackHelpers.test.js +37 -0
- package/test/unit/renderCondition.test.js +240 -0
- package/test/unit/renderTransformation.test.js +69 -0
- package/test/unit/webpack-modules/WrmDependencyModule.test.js +24 -0
- package/test/use-cases/.eslintrc +14 -0
- package/test/use-cases/asset-content-type/asset-content-type.test.js +50 -0
- package/test/use-cases/asset-content-type/src/app.js +8 -0
- package/test/use-cases/asset-content-type/src/ice.png +0 -0
- package/test/use-cases/asset-content-type/src/rect.svg +4 -0
- package/test/use-cases/asset-content-type/webpack.config.js +33 -0
- package/test/use-cases/asset-loading-via-js/asset-loading-via-js.test.js +61 -0
- package/test/use-cases/asset-loading-via-js/src/app.js +8 -0
- package/test/use-cases/asset-loading-via-js/src/ice.png +0 -0
- package/test/use-cases/asset-loading-via-js/src/rect.svg +4 -0
- package/test/use-cases/asset-loading-via-js/webpack.config.js +31 -0
- package/test/use-cases/associations-complex/associations-complex.test.js +82 -0
- package/test/use-cases/associations-complex/package-lock.json +73 -0
- package/test/use-cases/associations-complex/package.json +9 -0
- package/test/use-cases/associations-complex/src/copied-file-should-be-ignored.js +0 -0
- package/test/use-cases/associations-complex/src/entry.js +5 -0
- package/test/use-cases/associations-complex/src/entry2.js +5 -0
- package/test/use-cases/associations-complex/src/qunit.tests.js +2 -0
- package/test/use-cases/associations-complex/src/to-be-chunked.js +1 -0
- package/test/use-cases/associations-complex/webpack.config.js +48 -0
- package/test/use-cases/associations-simple/associations-simple.test.js +65 -0
- package/test/use-cases/associations-simple/package-lock.json +69 -0
- package/test/use-cases/associations-simple/package.json +5 -0
- package/test/use-cases/associations-simple/src/simple.js +3 -0
- package/test/use-cases/associations-simple/webpack.config.js +27 -0
- package/test/use-cases/async-chunks/async-chunks.test.js +113 -0
- package/test/use-cases/async-chunks/src/app.js +9 -0
- package/test/use-cases/async-chunks/src/async-bar.js +4 -0
- package/test/use-cases/async-chunks/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks/webpack.config.js +40 -0
- package/test/use-cases/async-chunks-named-context/async-chunks-named-context.test.js +76 -0
- package/test/use-cases/async-chunks-named-context/src/app.js +9 -0
- package/test/use-cases/async-chunks-named-context/src/app2.js +5 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-named-context/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-named-context/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-named-context/webpack.config.js +43 -0
- package/test/use-cases/async-chunks-of-async-chunks/async-chunks-of-async-chunks.test.js +117 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/app.js +9 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-of-async-chunks/webpack.config.js +43 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/async-chunks-of-async-chunks-with-multiple-entrypoints.test.js +156 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app.js +9 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app2.js +5 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/webpack.config.js +43 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/css-and-assets-distribution-via-mini-css-extract-plugin.test.js +72 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app.js +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app2.js +6 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice2.jpg +0 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect.svg +4 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect2.svg +4 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles.css +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles2.css +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/webpack.config.js +51 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/css-and-assets-via-extract-text-plugin.test.js +87 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.css +7 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.js +3 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.css +3 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.js +1 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/webpack.config.js +46 -0
- package/test/use-cases/css-and-assets-via-style-loader/css-and-assets-via-style-loader.test.js +46 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/app.js +6 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/styles.css +7 -0
- package/test/use-cases/css-and-assets-via-style-loader/webpack.config.js +46 -0
- package/test/use-cases/cyclic-dependencies/cyclic.test.js +24 -0
- package/test/use-cases/cyclic-dependencies/src/a.js +3 -0
- package/test/use-cases/cyclic-dependencies/src/b.js +3 -0
- package/test/use-cases/cyclic-dependencies/src/root.js +3 -0
- package/test/use-cases/cyclic-dependencies/webpack.config.js +24 -0
- package/test/use-cases/data-providers/data-providers.test.js +111 -0
- package/test/use-cases/data-providers/src/first.js +2 -0
- package/test/use-cases/data-providers/src/second.js +2 -0
- package/test/use-cases/data-providers/src/third.js +2 -0
- package/test/use-cases/data-providers/webpack.config.js +73 -0
- package/test/use-cases/data-providers/webpack.config.with-map.js +33 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/ensure-runtime-overwrite-of-mini-css-extract-plugin.test.js +86 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app.js +5 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app2.js +5 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice.png +0 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice2.jpg +0 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect.svg +4 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect2.svg +4 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles.css +8 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles2.css +8 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.after.config.js +51 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.before.config.js +51 -0
- package/test/use-cases/jsonp-function-name/jsonp-function-name.test.js +37 -0
- package/test/use-cases/jsonp-function-name/src/app.js +1 -0
- package/test/use-cases/jsonp-function-name/src/foo.js +2 -0
- package/test/use-cases/jsonp-function-name/webpack.config.js +35 -0
- package/test/use-cases/jsonp-function-name-default/jsonp-function-name-default.test.js +39 -0
- package/test/use-cases/jsonp-function-name-default/src/app.js +1 -0
- package/test/use-cases/jsonp-function-name-default/src/foo.js +2 -0
- package/test/use-cases/jsonp-function-name-default/webpack.config.js +34 -0
- package/test/use-cases/location-prefix/location-prefix.test.js +29 -0
- package/test/use-cases/location-prefix/src/simple.js +6 -0
- package/test/use-cases/location-prefix/webpack.config.js +25 -0
- package/test/use-cases/provided-module-replacement/provided-module-replacement.test.js +63 -0
- package/test/use-cases/provided-module-replacement/src/app.js +3 -0
- package/test/use-cases/provided-module-replacement/webpack.config.with-map.js +33 -0
- package/test/use-cases/provided-module-replacement/webpack.config.with-object.js +34 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/provided-modules-replacement-with-amd-target.test.js +62 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/src/app.js +3 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/webpack.config.js +41 -0
- package/test/use-cases/qunit-test-wrm-web-resource/qunit-test-wrm-web-resource.test.js +157 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/app.2.js +6 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/app.js +8 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep.js +8 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep_test.js +1 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-async.js +3 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep.js +4 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep_test.js +1 -0
- package/test/use-cases/qunit-test-wrm-web-resource/webpack.config.js +24 -0
- package/test/use-cases/resource-parameters/resource-parameters.test.js +77 -0
- package/test/use-cases/resource-parameters/src/app.js +12 -0
- package/test/use-cases/resource-parameters/src/ice.png +0 -0
- package/test/use-cases/resource-parameters/src/ice2.jpg +0 -0
- package/test/use-cases/resource-parameters/src/rect.svg +4 -0
- package/test/use-cases/resource-parameters/webpack.config.js +62 -0
- package/test/use-cases/resource-parameters/webpack.svg.config.js +30 -0
- package/test/use-cases/simple/simple.test.js +83 -0
- package/test/use-cases/simple/src/simple.js +3 -0
- package/test/use-cases/simple/webpack.config.js +24 -0
- package/test/use-cases/single-runtime-chunk/single-runtime-chunk.test.js +132 -0
- package/test/use-cases/single-runtime-chunk/src/first.js +2 -0
- package/test/use-cases/single-runtime-chunk/src/second.js +2 -0
- package/test/use-cases/single-runtime-chunk/src/shared.js +3 -0
- package/test/use-cases/single-runtime-chunk/src/third.js +2 -0
- package/test/use-cases/single-runtime-chunk/webpack.config.js +33 -0
- package/test/use-cases/specify-asset-dev-hash/specify-asset-dev-hash.test.js +33 -0
- package/test/use-cases/specify-asset-dev-hash/src/feature.js +6 -0
- package/test/use-cases/specify-asset-dev-hash/src/library.js +6 -0
- package/test/use-cases/specify-asset-dev-hash/webpack.config.js +71 -0
- package/test/use-cases/specify-conditions/specify-conditions.test.js +106 -0
- package/test/use-cases/specify-conditions/src/app.js +5 -0
- package/test/use-cases/specify-conditions/webpack.config.js +65 -0
- package/test/use-cases/specify-explicit-context/specify-explicit-context.test.js +89 -0
- package/test/use-cases/specify-explicit-context/src/app.js +5 -0
- package/test/use-cases/specify-explicit-context/webpack.config.js +34 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/specify-explicit-context-no-autogenerated.test.js +84 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/src/app.js +5 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/webpack.config.js +35 -0
- package/test/use-cases/specify-explicit-name/specify-explicit-name.test.js +110 -0
- package/test/use-cases/specify-explicit-name/src/app.js +5 -0
- package/test/use-cases/specify-explicit-name/webpack.config.js +43 -0
- package/test/use-cases/specify-explicit-state/specify-explicit-state.test.js +96 -0
- package/test/use-cases/specify-explicit-state/src/app.js +5 -0
- package/test/use-cases/specify-explicit-state/webpack.config.js +51 -0
- package/test/use-cases/specify-transformation/disable-transformations.test.js +77 -0
- package/test/use-cases/specify-transformation/extend-transformations.test.js +69 -0
- package/test/use-cases/specify-transformation/specify-transformation.test.js +100 -0
- package/test/use-cases/specify-transformation/src/app.js +13 -0
- package/test/use-cases/specify-transformation/src/ice.png +0 -0
- package/test/use-cases/specify-transformation/src/rect.svg +4 -0
- package/test/use-cases/specify-transformation/src/test.html +1 -0
- package/test/use-cases/specify-transformation/src/test.less +1 -0
- package/test/use-cases/specify-transformation/src/test.txt +1 -0
- package/test/use-cases/specify-transformation/webpack.disable-tranformations.config.js +31 -0
- package/test/use-cases/specify-transformation/webpack.extend-tranformations.config.js +34 -0
- package/test/use-cases/specify-transformation/webpack.specify-transformations.config.js +35 -0
- package/test/use-cases/split-chunks/split-chunks.test.js +102 -0
- package/test/use-cases/split-chunks/src/app.js +7 -0
- package/test/use-cases/split-chunks/src/app2.js +7 -0
- package/test/use-cases/split-chunks/src/bar.js +2 -0
- package/test/use-cases/split-chunks/src/foo.js +2 -0
- package/test/use-cases/split-chunks/src/foo2.js +2 -0
- package/test/use-cases/split-chunks/webpack.config.js +42 -0
- package/test/use-cases/split-chunks-with-runtime/split-chunks-with-runtime.test.js +114 -0
- package/test/use-cases/split-chunks-with-runtime/src/app.js +7 -0
- package/test/use-cases/split-chunks-with-runtime/src/app2.js +7 -0
- package/test/use-cases/split-chunks-with-runtime/src/bar.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/src/foo.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/src/foo2.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/webpack.config.js +43 -0
- package/test/use-cases/split-chunks-with-tests/split-chunks-with-tests.test.js +216 -0
- package/test/use-cases/split-chunks-with-tests/src/app.js +7 -0
- package/test/use-cases/split-chunks-with-tests/src/app2.js +7 -0
- package/test/use-cases/split-chunks-with-tests/src/bar.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/bar_test.js +1 -0
- package/test/use-cases/split-chunks-with-tests/src/foo.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/foo2.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/foo_test.js +1 -0
- package/test/use-cases/split-chunks-with-tests/webpack.config.js +43 -0
- package/test/use-cases/standalone/src/standalone-1.js +1 -0
- package/test/use-cases/standalone/src/standalone-2.js +1 -0
- package/test/use-cases/standalone/standalone.test.js +53 -0
- package/test/use-cases/standalone/webpack.config.js +25 -0
- package/test/use-cases/wrm-dependency-loading/src-amd/app.js +7 -0
- package/test/use-cases/wrm-dependency-loading/src-es6/app.js +7 -0
- package/test/use-cases/wrm-dependency-loading/webpack.config.amd.js +22 -0
- package/test/use-cases/wrm-dependency-loading/webpack.config.es6.js +22 -0
- package/test/use-cases/wrm-dependency-loading/wrm-dependency-loading.test.js +60 -0
- package/test/use-cases/wrm-manifest-path/src/a.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/app.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/app2.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/b.js +3 -0
- package/test/use-cases/wrm-manifest-path/webpack.config.js +27 -0
- package/test/use-cases/wrm-manifest-path/wrm-manifest-path.test.js +57 -0
- package/test/use-cases/wrm-resource-loading/src-amd/app.js +6 -0
- package/test/use-cases/wrm-resource-loading/src-es6/app.js +5 -0
- package/test/use-cases/wrm-resource-loading/src-relative/app.js +5 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.amd.js +23 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.es6.js +23 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.relative.js +23 -0
- package/test/use-cases/wrm-resource-loading/wrm-resource-loading.test.js +89 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const assert = require('chai').assert;
|
|
2
|
+
const parse = require('xml-parser');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const targetDir = path.join(__dirname, 'target');
|
|
8
|
+
const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
|
|
9
|
+
|
|
10
|
+
describe('specify-explicit-context', function() {
|
|
11
|
+
const config = require('./webpack.config.js');
|
|
12
|
+
|
|
13
|
+
let stats;
|
|
14
|
+
let error;
|
|
15
|
+
let wrNodes;
|
|
16
|
+
|
|
17
|
+
function getWebresourceLike(needle) {
|
|
18
|
+
return wrNodes.find(n => n.attributes.key.indexOf(needle) > -1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getContexts(node) {
|
|
22
|
+
return node.children.filter(n => n.name === 'context');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getContent(nodes) {
|
|
26
|
+
return nodes.map(n => n.content);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(done => {
|
|
30
|
+
webpack(config, (err, st) => {
|
|
31
|
+
error = err;
|
|
32
|
+
stats = st;
|
|
33
|
+
|
|
34
|
+
const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
|
|
35
|
+
const results = parse(xmlFile);
|
|
36
|
+
wrNodes = results.root.children.filter(n => n.attributes.key.startsWith('entry'));
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should run without error', () => {
|
|
42
|
+
assert.ok(wrNodes);
|
|
43
|
+
assert.equal(stats.hasErrors(), false);
|
|
44
|
+
assert.equal(stats.hasWarnings(), false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should add additional contexts as specified in the contextMap', () => {
|
|
48
|
+
const wrWithGoodConfig = getWebresourceLike('good-newcontexts');
|
|
49
|
+
const contexts = getContent(getContexts(wrWithGoodConfig));
|
|
50
|
+
assert.ok(contexts);
|
|
51
|
+
assert.equal(contexts.length, 3);
|
|
52
|
+
assert.include(contexts, 'some:weird:context');
|
|
53
|
+
assert.include(contexts, 'foo.bar');
|
|
54
|
+
assert.include(contexts, 'app-good-newcontexts');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should add the entrypoint name as a context when there is no contextMap config for it', () => {
|
|
58
|
+
const wrWithImplicitConfig = getWebresourceLike('good-implicit');
|
|
59
|
+
const contexts = getContent(getContexts(wrWithImplicitConfig));
|
|
60
|
+
assert.ok(contexts);
|
|
61
|
+
assert.equal(contexts.length, 1);
|
|
62
|
+
assert.include(contexts, 'app-good-implicit');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should ignore non-array configuration values gracefully', () => {
|
|
66
|
+
const wrWithBadConfig = getWebresourceLike('bad-objectlike');
|
|
67
|
+
const contexts = getContent(getContexts(wrWithBadConfig));
|
|
68
|
+
assert.ok(contexts);
|
|
69
|
+
assert.equal(contexts.length, 1);
|
|
70
|
+
assert.include(contexts, 'app-bad-objectlike');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should ignore falsy configuration values gracefully', () => {
|
|
74
|
+
const wrWithBadConfig = getWebresourceLike('bad-falsy');
|
|
75
|
+
const contexts = getContent(getContexts(wrWithBadConfig));
|
|
76
|
+
assert.ok(contexts);
|
|
77
|
+
assert.equal(contexts.length, 1);
|
|
78
|
+
assert.include(contexts, 'app-bad-falsy');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should ignore non-string context names gracefully', () => {
|
|
82
|
+
const wrWithBadValues = getWebresourceLike('bad-emptyvalues');
|
|
83
|
+
const contexts = getContent(getContexts(wrWithBadValues));
|
|
84
|
+
assert.ok(contexts);
|
|
85
|
+
assert.equal(contexts.length, 2);
|
|
86
|
+
assert.include(contexts, 'app-bad-emptyvalues');
|
|
87
|
+
assert.include(contexts, 'foo.bar');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const WrmPlugin = require('../../../src/WrmPlugin');
|
|
3
|
+
const FRONTEND_SRC_DIR = path.join(__dirname, 'src');
|
|
4
|
+
const OUTPUT_DIR = path.join(__dirname, 'target');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
mode: 'development',
|
|
8
|
+
entry: {
|
|
9
|
+
'app-good-newcontexts': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
10
|
+
'app-good-implicit': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
11
|
+
'app-bad-emptyarray': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
12
|
+
'app-bad-emptyvalues': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
13
|
+
'app-bad-objectlike': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
14
|
+
'app-bad-falsy': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
15
|
+
},
|
|
16
|
+
plugins: [
|
|
17
|
+
new WrmPlugin({
|
|
18
|
+
pluginKey: 'com.atlassian.plugin.test',
|
|
19
|
+
xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
|
|
20
|
+
contextMap: {
|
|
21
|
+
'app-good-newcontexts': ['some:weird:context', 'foo.bar'],
|
|
22
|
+
'app-bad-emptyarray': [],
|
|
23
|
+
'app-bad-emptyvalues': [false, '', undefined, 'foo.bar'],
|
|
24
|
+
'app-bad-objectlike': {},
|
|
25
|
+
'app-bad-falsy': '',
|
|
26
|
+
},
|
|
27
|
+
verbose: false,
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
output: {
|
|
31
|
+
filename: '[name].js',
|
|
32
|
+
path: OUTPUT_DIR,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const assert = require('chai').assert;
|
|
2
|
+
const parse = require('xml-parser');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const targetDir = path.join(__dirname, 'target');
|
|
8
|
+
const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
|
|
9
|
+
|
|
10
|
+
describe('specify-explicit-context (with no auto-generated values)', function() {
|
|
11
|
+
const config = require('./webpack.config.js');
|
|
12
|
+
|
|
13
|
+
let stats;
|
|
14
|
+
let error;
|
|
15
|
+
let wrNodes;
|
|
16
|
+
|
|
17
|
+
function getWebresourceLike(needle) {
|
|
18
|
+
return wrNodes.find(n => n.attributes.key.indexOf(needle) > -1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getContexts(node) {
|
|
22
|
+
return node.children.filter(n => n.name === 'context');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getContent(nodes) {
|
|
26
|
+
return nodes.map(n => n.content);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(done => {
|
|
30
|
+
webpack(config, (err, st) => {
|
|
31
|
+
error = err;
|
|
32
|
+
stats = st;
|
|
33
|
+
|
|
34
|
+
const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
|
|
35
|
+
const results = parse(xmlFile);
|
|
36
|
+
wrNodes = results.root.children.filter(n => n.attributes.key.startsWith('entry'));
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should run without error', () => {
|
|
42
|
+
assert.ok(wrNodes);
|
|
43
|
+
assert.equal(stats.hasErrors(), false);
|
|
44
|
+
assert.equal(stats.hasWarnings(), false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should add additional contexts as specified in the contextMap', () => {
|
|
48
|
+
const wrWithGoodConfig = getWebresourceLike('good-newcontexts');
|
|
49
|
+
const contexts = getContent(getContexts(wrWithGoodConfig));
|
|
50
|
+
assert.ok(contexts);
|
|
51
|
+
assert.include(contexts, 'some:weird:context');
|
|
52
|
+
assert.include(contexts, 'foo.bar');
|
|
53
|
+
assert.notInclude(contexts, 'app-good-newcontexts');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should add the entrypoint name as a context when there is no contextMap config for it', () => {
|
|
57
|
+
const wrWithImplicitConfig = getWebresourceLike('good-implicit');
|
|
58
|
+
const contexts = getContent(getContexts(wrWithImplicitConfig));
|
|
59
|
+
assert.ok(contexts);
|
|
60
|
+
assert.equal(contexts.length, 0);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should ignore non-array configuration values gracefully', () => {
|
|
64
|
+
const wrWithBadConfig = getWebresourceLike('bad-objectlike');
|
|
65
|
+
const contexts = getContent(getContexts(wrWithBadConfig));
|
|
66
|
+
assert.ok(contexts);
|
|
67
|
+
assert.equal(contexts.length, 0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should ignore falsy configuration values gracefully', () => {
|
|
71
|
+
const wrWithBadConfig = getWebresourceLike('bad-falsy');
|
|
72
|
+
const contexts = getContent(getContexts(wrWithBadConfig));
|
|
73
|
+
assert.ok(contexts);
|
|
74
|
+
assert.equal(contexts.length, 0);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should ignore non-string context names gracefully', () => {
|
|
78
|
+
const wrWithBadValues = getWebresourceLike('bad-emptyvalues');
|
|
79
|
+
const contexts = getContent(getContexts(wrWithBadValues));
|
|
80
|
+
assert.ok(contexts);
|
|
81
|
+
assert.include(contexts, 'foo.bar');
|
|
82
|
+
assert.notInclude(contexts, 'app-bad-emptyvalues');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const WrmPlugin = require('../../../src/WrmPlugin');
|
|
3
|
+
const FRONTEND_SRC_DIR = path.join(__dirname, 'src');
|
|
4
|
+
const OUTPUT_DIR = path.join(__dirname, 'target');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
mode: 'development',
|
|
8
|
+
entry: {
|
|
9
|
+
'app-good-newcontexts': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
10
|
+
'app-good-implicit': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
11
|
+
'app-bad-emptyarray': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
12
|
+
'app-bad-emptyvalues': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
13
|
+
'app-bad-objectlike': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
14
|
+
'app-bad-falsy': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
15
|
+
},
|
|
16
|
+
plugins: [
|
|
17
|
+
new WrmPlugin({
|
|
18
|
+
pluginKey: 'com.atlassian.plugin.test',
|
|
19
|
+
xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
|
|
20
|
+
addEntrypointNameAsContext: false,
|
|
21
|
+
contextMap: {
|
|
22
|
+
'app-good-newcontexts': ['some:weird:context', 'foo.bar'],
|
|
23
|
+
'app-bad-emptyarray': [],
|
|
24
|
+
'app-bad-emptyvalues': [false, '', undefined, 'foo.bar'],
|
|
25
|
+
'app-bad-objectlike': {},
|
|
26
|
+
'app-bad-falsy': '',
|
|
27
|
+
},
|
|
28
|
+
verbose: false,
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
output: {
|
|
32
|
+
filename: '[name].js',
|
|
33
|
+
path: OUTPUT_DIR,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const assert = require('chai').assert;
|
|
2
|
+
const parse = require('xml-parser');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const targetDir = path.join(__dirname, 'target');
|
|
8
|
+
const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
|
|
9
|
+
|
|
10
|
+
describe('specify-explicit-webresource-name', function() {
|
|
11
|
+
const config = require('./webpack.config.js');
|
|
12
|
+
|
|
13
|
+
let stats;
|
|
14
|
+
let wrNodes;
|
|
15
|
+
|
|
16
|
+
function findWrEndingWith(key) {
|
|
17
|
+
return wrNodes.find(n => n.attributes.key.endsWith(key));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
beforeEach(done => {
|
|
21
|
+
webpack(config, (err, st) => {
|
|
22
|
+
stats = st;
|
|
23
|
+
|
|
24
|
+
const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
|
|
25
|
+
const results = parse(xmlFile);
|
|
26
|
+
wrNodes = results.root.children.filter(n => n.name === 'web-resource');
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should work without error', () => {
|
|
32
|
+
assert.notEqual(wrNodes.length, 0);
|
|
33
|
+
assert.equal(stats.hasErrors(), false);
|
|
34
|
+
assert.equal(stats.hasWarnings(), false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should create a webresource with an explicit name when it is mapped in config', () => {
|
|
38
|
+
let node = findWrEndingWith('mapped-with-string');
|
|
39
|
+
assert.exists(node);
|
|
40
|
+
assert.propertyVal(node.attributes, 'key', 'customkey-mapped-with-string');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should create a webresource with an explicit key when it is mapped in config', () => {
|
|
44
|
+
let node = findWrEndingWith('mapped-with-object');
|
|
45
|
+
assert.exists(node);
|
|
46
|
+
assert.propertyVal(node.attributes, 'key', 'customkey-mapped-with-object');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should create a webresource with an explicit name when it is mapped in config', () => {
|
|
50
|
+
let node = findWrEndingWith('mapped-with-object-with-only-name');
|
|
51
|
+
assert.exists(node);
|
|
52
|
+
assert.property(
|
|
53
|
+
node.attributes,
|
|
54
|
+
'key',
|
|
55
|
+
'entrypoint-app-good-mapped-with-object-with-only-name',
|
|
56
|
+
'no "key" was provided so should be auto-generated'
|
|
57
|
+
);
|
|
58
|
+
assert.propertyVal(
|
|
59
|
+
node.attributes,
|
|
60
|
+
'name',
|
|
61
|
+
'Legacy Name for App 2',
|
|
62
|
+
'should use the configured value for "name"'
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should create a webresource with an explicit key and name when it is mapped in config', () => {
|
|
67
|
+
let node = findWrEndingWith('mapped-with-object-with-name');
|
|
68
|
+
assert.exists(node);
|
|
69
|
+
assert.propertyVal(
|
|
70
|
+
node.attributes,
|
|
71
|
+
'key',
|
|
72
|
+
'customkey-mapped-with-object-with-name',
|
|
73
|
+
'should use the configured value for "key"'
|
|
74
|
+
);
|
|
75
|
+
assert.propertyVal(
|
|
76
|
+
node.attributes,
|
|
77
|
+
'name',
|
|
78
|
+
'Legacy Name for App 1',
|
|
79
|
+
'should use the configured value for "name"'
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should auto-generate the name if there is no config provided', () => {
|
|
84
|
+
let node = findWrEndingWith('app-good-autonamed');
|
|
85
|
+
assert.exists(node);
|
|
86
|
+
assert.propertyVal(
|
|
87
|
+
node.attributes,
|
|
88
|
+
'key',
|
|
89
|
+
'entrypoint-app-good-autonamed',
|
|
90
|
+
'there was no mapping for this web-resource, so the key is auto-generated'
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should auto-generate the name when the supplied value is not a string', () => {
|
|
95
|
+
let badNodes = wrNodes.filter(n => n.attributes.key.startsWith('entrypoint-app-bad'));
|
|
96
|
+
assert.equal(badNodes.length, 2);
|
|
97
|
+
assert.propertyVal(
|
|
98
|
+
badNodes[0].attributes,
|
|
99
|
+
'key',
|
|
100
|
+
'entrypoint-app-bad-objectlike',
|
|
101
|
+
'an object is not a string, so the key is auto-generated'
|
|
102
|
+
);
|
|
103
|
+
assert.propertyVal(
|
|
104
|
+
badNodes[1].attributes,
|
|
105
|
+
'key',
|
|
106
|
+
'entrypoint-app-bad-falsy',
|
|
107
|
+
'falsy values are not strings, so the key is auto-generated'
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const WrmPlugin = require('../../../src/WrmPlugin');
|
|
3
|
+
const FRONTEND_SRC_DIR = path.join(__dirname, 'src');
|
|
4
|
+
const OUTPUT_DIR = path.join(__dirname, 'target');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
mode: 'development',
|
|
8
|
+
entry: {
|
|
9
|
+
'app-good-mapped-with-string': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
10
|
+
'app-good-mapped-with-object': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
11
|
+
'app-good-mapped-with-object-with-name': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
12
|
+
'app-good-mapped-with-object-with-only-name': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
13
|
+
'app-good-autonamed': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
14
|
+
'app-bad-objectlike': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
15
|
+
'app-bad-falsy': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
new WrmPlugin({
|
|
19
|
+
pluginKey: 'com.atlassian.plugin.test',
|
|
20
|
+
xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
|
|
21
|
+
webresourceKeyMap: {
|
|
22
|
+
'app-good-mapped-with-string': 'customkey-mapped-with-string',
|
|
23
|
+
'app-good-mapped-with-object': {
|
|
24
|
+
key: 'customkey-mapped-with-object',
|
|
25
|
+
},
|
|
26
|
+
'app-good-mapped-with-object-with-name': {
|
|
27
|
+
key: 'customkey-mapped-with-object-with-name',
|
|
28
|
+
name: 'Legacy Name for App 1',
|
|
29
|
+
},
|
|
30
|
+
'app-good-mapped-with-object-with-only-name': {
|
|
31
|
+
name: 'Legacy Name for App 2',
|
|
32
|
+
},
|
|
33
|
+
'app-bad-objectlike': {},
|
|
34
|
+
'app-bad-falsy': '',
|
|
35
|
+
},
|
|
36
|
+
verbose: false,
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
output: {
|
|
40
|
+
filename: '[name].js',
|
|
41
|
+
path: OUTPUT_DIR,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const assert = require('chai').assert;
|
|
2
|
+
const parse = require('xml-parser');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const targetDir = path.join(__dirname, 'target');
|
|
8
|
+
const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
|
|
9
|
+
|
|
10
|
+
describe('specify-explicit-webresource-state', function() {
|
|
11
|
+
const config = require('./webpack.config.js');
|
|
12
|
+
|
|
13
|
+
let stats;
|
|
14
|
+
let wrNodes;
|
|
15
|
+
|
|
16
|
+
function findWrEndingWith(key) {
|
|
17
|
+
return wrNodes.find(n => n.attributes.key.endsWith(key));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
beforeEach(done => {
|
|
21
|
+
webpack(config, (err, st) => {
|
|
22
|
+
stats = st;
|
|
23
|
+
|
|
24
|
+
const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
|
|
25
|
+
const results = parse(xmlFile);
|
|
26
|
+
wrNodes = results.root.children.filter(node => node.name === 'web-resource');
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should work without error', () => {
|
|
32
|
+
assert.notEqual(wrNodes.length, 0);
|
|
33
|
+
assert.equal(stats.hasErrors(), false);
|
|
34
|
+
assert.equal(stats.hasWarnings(), false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('providing a plain string', () => {
|
|
38
|
+
it('should create a webresource with an implicit state', () => {
|
|
39
|
+
const node = findWrEndingWith('plain-string');
|
|
40
|
+
assert.exists(node);
|
|
41
|
+
assert.notProperty(
|
|
42
|
+
node.attributes,
|
|
43
|
+
'state',
|
|
44
|
+
'WRM assumes missing state means enabled, so attribute is unneeded'
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('providing only a key', () => {
|
|
50
|
+
it('should create a webresource with an implicit state', () => {
|
|
51
|
+
const node = findWrEndingWith('only-key');
|
|
52
|
+
assert.exists(node);
|
|
53
|
+
assert.notProperty(
|
|
54
|
+
node.attributes,
|
|
55
|
+
'state',
|
|
56
|
+
'WRM assumes missing state means enabled, so attribute is unneeded'
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('providing only a state', () => {
|
|
62
|
+
it('should create a webresource with an explicit state', () => {
|
|
63
|
+
const node = findWrEndingWith('only-state');
|
|
64
|
+
assert.exists(node);
|
|
65
|
+
assert.propertyVal(node.attributes, 'state', 'disabled');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should interpret a boolean of "true" as enabled', () => {
|
|
69
|
+
const node = findWrEndingWith('only-state-boolean-enabled');
|
|
70
|
+
assert.exists(node);
|
|
71
|
+
assert.propertyVal(node.attributes, 'state', 'enabled');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should interpret a boolean of "false" as disabled', () => {
|
|
75
|
+
const node = findWrEndingWith('only-state-boolean-disabled');
|
|
76
|
+
assert.exists(node);
|
|
77
|
+
assert.propertyVal(node.attributes, 'state', 'disabled');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('providing an explicit key and state', () => {
|
|
82
|
+
it('should create a webresource with explicit values when the state is "enabled"', () => {
|
|
83
|
+
const node = findWrEndingWith('key-state-enabled');
|
|
84
|
+
assert.exists(node);
|
|
85
|
+
assert.propertyVal(node.attributes, 'key', 'customkey-key-state-enabled');
|
|
86
|
+
assert.propertyVal(node.attributes, 'state', 'enabled');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should create a webresource with explicit values when the state is "disabled"', () => {
|
|
90
|
+
const node = findWrEndingWith('key-state-disabled');
|
|
91
|
+
assert.exists(node);
|
|
92
|
+
assert.propertyVal(node.attributes, 'key', 'customkey-key-state-disabled');
|
|
93
|
+
assert.propertyVal(node.attributes, 'state', 'disabled');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const WrmPlugin = require('../../../src/WrmPlugin');
|
|
3
|
+
const FRONTEND_SRC_DIR = path.join(__dirname, 'src');
|
|
4
|
+
const OUTPUT_DIR = path.join(__dirname, 'target');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
mode: 'development',
|
|
8
|
+
entry: {
|
|
9
|
+
'plain-string': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
10
|
+
'only-key': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
11
|
+
'only-state': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
12
|
+
'only-state-boolean-enabled': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
13
|
+
'only-state-boolean-disabled': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
14
|
+
'key-state-enabled': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
15
|
+
'key-state-disabled': path.join(FRONTEND_SRC_DIR, 'app.js'),
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
new WrmPlugin({
|
|
19
|
+
pluginKey: 'com.atlassian.plugin.test',
|
|
20
|
+
xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
|
|
21
|
+
webresourceKeyMap: {
|
|
22
|
+
'plain-string': 'customkey-plain-string',
|
|
23
|
+
'only-key': {
|
|
24
|
+
key: 'customkey-only-key',
|
|
25
|
+
},
|
|
26
|
+
'only-state': {
|
|
27
|
+
state: 'disabled',
|
|
28
|
+
},
|
|
29
|
+
'only-state-boolean-enabled': {
|
|
30
|
+
state: true,
|
|
31
|
+
},
|
|
32
|
+
'only-state-boolean-disabled': {
|
|
33
|
+
state: false,
|
|
34
|
+
},
|
|
35
|
+
'key-state-enabled': {
|
|
36
|
+
key: 'customkey-key-state-enabled',
|
|
37
|
+
state: 'enabled',
|
|
38
|
+
},
|
|
39
|
+
'key-state-disabled': {
|
|
40
|
+
key: 'customkey-key-state-disabled',
|
|
41
|
+
state: 'disabled',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
verbose: false,
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
47
|
+
output: {
|
|
48
|
+
filename: '[name].js',
|
|
49
|
+
path: OUTPUT_DIR,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const assert = require('chai').assert;
|
|
2
|
+
const parse = require('xml-parser');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const targetDir = path.join(__dirname, 'target');
|
|
8
|
+
const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
|
|
9
|
+
|
|
10
|
+
describe('specify-transformation', function() {
|
|
11
|
+
const config = require('./webpack.disable-tranformations.config');
|
|
12
|
+
|
|
13
|
+
let stats;
|
|
14
|
+
let error;
|
|
15
|
+
let wrNodes;
|
|
16
|
+
|
|
17
|
+
function getWebresourceLike(needle) {
|
|
18
|
+
return wrNodes.find(n => n.attributes.key.indexOf(needle) > -1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getTransformation(node) {
|
|
22
|
+
return node.children.filter(childNode => childNode.name === 'transformation');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getTransformationByExtension(transformations, extname) {
|
|
26
|
+
return transformations.filter(transformation => transformation.attributes.extension === extname)[0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(done => {
|
|
30
|
+
webpack(config, (err, st) => {
|
|
31
|
+
error = err;
|
|
32
|
+
stats = st;
|
|
33
|
+
|
|
34
|
+
const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
|
|
35
|
+
const results = parse(xmlFile);
|
|
36
|
+
wrNodes = results.root.children;
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('disabling transformations', () => {
|
|
42
|
+
let entryJsTrans, entrySoyTrans, entryLessTrans;
|
|
43
|
+
let jsTrans, htmlTrans, lessTrans, soyTrans, svgTrans, txtTrans;
|
|
44
|
+
|
|
45
|
+
beforeEach(function() {
|
|
46
|
+
const entrypointTransformations = getTransformation(getWebresourceLike('app-one'));
|
|
47
|
+
const assetTransformations = getTransformation(getWebresourceLike('assets'));
|
|
48
|
+
|
|
49
|
+
assert.ok(entrypointTransformations);
|
|
50
|
+
assert.ok(assetTransformations);
|
|
51
|
+
|
|
52
|
+
entryJsTrans = getTransformationByExtension(entrypointTransformations, 'js');
|
|
53
|
+
entrySoyTrans = getTransformationByExtension(entrypointTransformations, 'soy');
|
|
54
|
+
entryLessTrans = getTransformationByExtension(entrypointTransformations, 'less');
|
|
55
|
+
|
|
56
|
+
jsTrans = getTransformationByExtension(assetTransformations, 'js');
|
|
57
|
+
htmlTrans = getTransformationByExtension(assetTransformations, 'html');
|
|
58
|
+
lessTrans = getTransformationByExtension(assetTransformations, 'less');
|
|
59
|
+
soyTrans = getTransformationByExtension(assetTransformations, 'soy');
|
|
60
|
+
svgTrans = getTransformationByExtension(assetTransformations, 'svg');
|
|
61
|
+
txtTrans = getTransformationByExtension(assetTransformations, 'txt');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should disable all transformations', () => {
|
|
65
|
+
assert.equal(entryJsTrans, null);
|
|
66
|
+
assert.equal(entryLessTrans, null);
|
|
67
|
+
assert.equal(entrySoyTrans, null);
|
|
68
|
+
|
|
69
|
+
assert.equal(jsTrans, null);
|
|
70
|
+
assert.equal(lessTrans, null);
|
|
71
|
+
assert.equal(htmlTrans, null);
|
|
72
|
+
assert.equal(soyTrans, null);
|
|
73
|
+
assert.equal(svgTrans, null);
|
|
74
|
+
assert.equal(txtTrans, null);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|