diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..4f0f147ff37a437455cfcf9230aa3e3e0005a1b2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# change logs + +## v0.3.2/v0.3.3 + +- Fix the path of babel-plugins + +## v0.3.1 + +- Fix defined a component repeatly. + +## v0.3.0 + +- A new loader for weex! The features are amazing! \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..cd76146d6212e1dca34b90c320b907422f8e11f3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2019 Apache Incubator-Weex + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000000000000000000000000000000000000..2264b2ea887927098b2f69d6e07a59de5092bc2d --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +Apache Weex (Incubating) +Copyright 2019 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/README.OpenSource b/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..8f5799392a76183b04a194358892bfa2834819ea --- /dev/null +++ b/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "weex-loader", + "License": "Apache-2.0", + "License File": "NOTICE", + "Version Number": " 0.7.12", + "Owner": "sunbingxin@huawei.com", + "Upstream URL": "https://github.com/apache/weex-loader.git", + "Description": "a webpack loader for weex." + } +] diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000000000000000000000000000000000000..446f8eb60916cf62edecbe8d2c3f6165f0eb534d --- /dev/null +++ b/circle.yml @@ -0,0 +1,7 @@ +machine: + node: + version: 4 + +test: + override: + - npm run build diff --git a/deps/weex-scripter/.gitignore b/deps/weex-scripter/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3ba3e2b1fd74648606fdd266b8e196741c1306f3 --- /dev/null +++ b/deps/weex-scripter/.gitignore @@ -0,0 +1,3 @@ +node_modules +coverage +.DS_Store diff --git a/deps/weex-scripter/.jscsrc b/deps/weex-scripter/.jscsrc new file mode 100644 index 0000000000000000000000000000000000000000..0a9b4660c81262162e3504b6b8269daaed6f4bd9 --- /dev/null +++ b/deps/weex-scripter/.jscsrc @@ -0,0 +1,31 @@ +{ + "preset": "node-style-guide", + + "disallowKeywordsOnNewLine": [], + "disallowMultipleVarDecl": {"allExcept": ["undefined"]}, + "disallowSemicolons": true, + "requireCapitalizedComments": null, + + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + + "disallowSpacesInFunction": null, + "disallowSpacesInNamedFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + + "disallowSpaceBeforeComma": true, + "requireCommaBeforeLineBreak": true, + "disallowTrailingComma": true, + "requireTrailingComma": null +} diff --git a/deps/weex-scripter/LICENSE b/deps/weex-scripter/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..6ec5ad138855ceb05e4e4e5350541d0bf9e9792d --- /dev/null +++ b/deps/weex-scripter/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2015-present, Weex Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/deps/weex-scripter/NOTICE b/deps/weex-scripter/NOTICE new file mode 100644 index 0000000000000000000000000000000000000000..04f3efb0aa654144930d711635a4a58338830074 --- /dev/null +++ b/deps/weex-scripter/NOTICE @@ -0,0 +1,7 @@ +Weex +Copyright 2016 Alibaba Group + +This product includes software developed at Alibaba Group. (http://www.alibabagroup.com) + +This product contains software (https://github.com/marcuswestin/require) developed +by Marcus Westin, licensed under the MIT License. diff --git a/deps/weex-scripter/README.md b/deps/weex-scripter/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d20b4418d1c1e2f40287f4b8800862e72182209f --- /dev/null +++ b/deps/weex-scripter/README.md @@ -0,0 +1,21 @@ +# Weex ` \ No newline at end of file diff --git a/test/spec/d.we b/test/spec/d.we new file mode 100644 index 0000000000000000000000000000000000000000..8d6c8f1684b0aca4084c0903df03428dc67d7b25 --- /dev/null +++ b/test/spec/d.we @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/spec/data.json b/test/spec/data.json new file mode 100644 index 0000000000000000000000000000000000000000..b8e9b405459d83a42e6cb43e3df1c44a0c9f89bd --- /dev/null +++ b/test/spec/data.json @@ -0,0 +1,3 @@ +{ + "name": "Weex" +} \ No newline at end of file diff --git a/test/spec/e.we b/test/spec/e.we new file mode 100644 index 0000000000000000000000000000000000000000..0c580f11d5356410c0b1a4fe8c8b3b131634c732 --- /dev/null +++ b/test/spec/e.we @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/example-list-item.we b/test/spec/example-list-item.we new file mode 100644 index 0000000000000000000000000000000000000000..1cc6e219b49ff94066f5cc8f99dbd6cb551e5f89 --- /dev/null +++ b/test/spec/example-list-item.we @@ -0,0 +1,27 @@ + + + + + \ No newline at end of file diff --git a/test/spec/example-list.we b/test/spec/example-list.we new file mode 100644 index 0000000000000000000000000000000000000000..f47e4e46c2ca5b963b1b329ee214f4a2cb15d4b9 --- /dev/null +++ b/test/spec/example-list.we @@ -0,0 +1,68 @@ + + + + + \ No newline at end of file diff --git a/test/spec/f.css b/test/spec/f.css new file mode 100644 index 0000000000000000000000000000000000000000..11d03bc5ade92e2c6f16f343a37d7fd3324b995c --- /dev/null +++ b/test/spec/f.css @@ -0,0 +1,3 @@ +.wrap { + flex-direction: row; +} \ No newline at end of file diff --git a/test/spec/f.html b/test/spec/f.html new file mode 100644 index 0000000000000000000000000000000000000000..3229bc9adee59c5c779be7a48b17fcd9feff1f31 --- /dev/null +++ b/test/spec/f.html @@ -0,0 +1,4 @@ +
+ + +
\ No newline at end of file diff --git a/test/spec/f.js b/test/spec/f.js new file mode 100644 index 0000000000000000000000000000000000000000..65d0da97893a75eca74c692d65874dace00d9ae1 --- /dev/null +++ b/test/spec/f.js @@ -0,0 +1,6 @@ +export function data() { + return { + hi: 'Hello', + name: 'Weex' + } +} \ No newline at end of file diff --git a/test/spec/f.we b/test/spec/f.we new file mode 100644 index 0000000000000000000000000000000000000000..b955e53da9bd621077e21111adbf23e2070e2c3e --- /dev/null +++ b/test/spec/f.we @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/test/spec/g.we b/test/spec/g.we new file mode 100644 index 0000000000000000000000000000000000000000..f4c462ef4bca263248c2207b473f52c3ffa7bfb1 --- /dev/null +++ b/test/spec/g.we @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file diff --git a/test/spec/getName.js b/test/spec/getName.js new file mode 100644 index 0000000000000000000000000000000000000000..8ef944caf6aa11c22430bd5cc82ccbee2e80e23a --- /dev/null +++ b/test/spec/getName.js @@ -0,0 +1 @@ +export default () => 'Weex' \ No newline at end of file diff --git a/test/spec/h.we b/test/spec/h.we new file mode 100644 index 0000000000000000000000000000000000000000..1bf7f581e1a386055d7603f3302feb89502fe714 --- /dev/null +++ b/test/spec/h.we @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/test/spec/hi.we b/test/spec/hi.we new file mode 100644 index 0000000000000000000000000000000000000000..88dbef1ae3b55e8e7b4a33f314b3790f05c68a3b --- /dev/null +++ b/test/spec/hi.we @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/test/spec/i.we b/test/spec/i.we new file mode 100644 index 0000000000000000000000000000000000000000..f0fc21f31f25456066a81427d79fee107dfbde7b --- /dev/null +++ b/test/spec/i.we @@ -0,0 +1,22 @@ + + + + + + + + + \ No newline at end of file diff --git a/test/spec/j.we b/test/spec/j.we new file mode 100644 index 0000000000000000000000000000000000000000..75d7cf99c27692685362b761f264f062b8b3f48b --- /dev/null +++ b/test/spec/j.we @@ -0,0 +1,28 @@ + + + + + \ No newline at end of file diff --git a/test/spec/k.we b/test/spec/k.we new file mode 100644 index 0000000000000000000000000000000000000000..88b1443fd0e940fbb466cb88baf87dedf26c6649 --- /dev/null +++ b/test/spec/k.we @@ -0,0 +1,43 @@ + + + + + \ No newline at end of file diff --git a/test/spec/l.we b/test/spec/l.we new file mode 100644 index 0000000000000000000000000000000000000000..95d14ccdedd39874ad81e3e194e98858ed56359b --- /dev/null +++ b/test/spec/l.we @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/test/spec/m.we b/test/spec/m.we new file mode 100644 index 0000000000000000000000000000000000000000..7f255422b3f01a6de884ba7f3a23f7c77d22c0ff --- /dev/null +++ b/test/spec/m.we @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/test/spec/n.we b/test/spec/n.we new file mode 100644 index 0000000000000000000000000000000000000000..b0b729240fe33ee7aafffa7a3c24a112d79e4702 --- /dev/null +++ b/test/spec/n.we @@ -0,0 +1,37 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/spec/name.css b/test/spec/name.css new file mode 100644 index 0000000000000000000000000000000000000000..3c6e476c5958a2d396979fa9b120845d9dc48031 --- /dev/null +++ b/test/spec/name.css @@ -0,0 +1,4 @@ +.name { + font-size: 26px; + color: red; +} \ No newline at end of file diff --git a/test/spec/name.html b/test/spec/name.html new file mode 100644 index 0000000000000000000000000000000000000000..258e5e5394667b07d4e37bb0d52f0412105a35df --- /dev/null +++ b/test/spec/name.html @@ -0,0 +1 @@ +
{{name}}
diff --git a/test/spec/name.js b/test/spec/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d52e5531ba566f662ba2f5afaa1158f1f8b335f8 --- /dev/null +++ b/test/spec/name.js @@ -0,0 +1,8 @@ +export default { + data() { + console.log('Name Component Comment') + return { + name: '' + } + } +} \ No newline at end of file diff --git a/test/spec/name.we b/test/spec/name.we new file mode 100644 index 0000000000000000000000000000000000000000..efa318e1009cd61b7d582b7d1522d477a749b3e0 --- /dev/null +++ b/test/spec/name.we @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/test/spec/o.we b/test/spec/o.we new file mode 100644 index 0000000000000000000000000000000000000000..af5af17b930dbc7e39564065dec846034d227b50 --- /dev/null +++ b/test/spec/o.we @@ -0,0 +1,54 @@ + + + \ No newline at end of file diff --git a/test/spec/toast.js b/test/spec/toast.js new file mode 100644 index 0000000000000000000000000000000000000000..af59d1b1ab7c54557c9914f6f48357fb571cf2a1 --- /dev/null +++ b/test/spec/toast.js @@ -0,0 +1,8 @@ +var modal +__weex_define__('@weex-component/toast', [], function(__weex_require__) { + modal = __weex_require__('@weex-module/modal') +}) + +module.exports = function(msg) { + modal.toast({message: msg}) +} \ No newline at end of file diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000000000000000000000000000000000000..6cb4c57ea8e871e5ff9db9717b7434361d17fa2f --- /dev/null +++ b/test/test.js @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +const fs = require('fs'); +const path =require('path'); + +const chai = require('chai'); +const sinon = require('sinon'); +const sinonChai = require('sinon-chai'); +const expect = chai.expect; +chai.use(sinonChai); + +const Base64 = require('js-base64').Base64; +const SourceMap = require('source-map'); + +function getActualString(name) { + const filepath = path.resolve(__dirname, 'actual', `${name}.js`); + const result = fs.readFileSync(filepath, 'utf-8'); + return result.toString(); +} + +function getExpectJSON(name) { + const filepath = path.resolve(__dirname, 'expect', `${name}.js`); + const result = fs.readFileSync(filepath, 'utf-8'); + return JSON.parse(result.toString()); +} + +function stringifyActual(json) { + return JSON.stringify(json, function(key, value) { + if (typeof value === 'function') { + value = value.toString(); + } + return value; + }, ' '); +} + +function extractMap(actualStr) { + const mapStr = actualStr.match(/\/\/\# sourceMappingURL=data:application\/json;charset=utf-8;base64,([0-9a-zA-Z=+\/]+)/) + if (mapStr) { + return JSON.parse(Base64.decode(mapStr[1])); + } +} + +describe('build', () => { + let __weex_define__; + let __weex_bootstrap__; + let components; + let requireStub; + let bootstrapStub; + + function expectActual(name) { + const actualStr = getActualString(name); + const fn = new Function('__weex_define__', '__weex_bootstrap__', actualStr); + fn(__weex_define__, __weex_bootstrap__); + + // const filepath = path.resolve(__dirname, 'expect', `${name}.js`); + // fs.writeFileSync(filepath, stringifyActual(components), 'utf-8'); + + const expectJSON = getExpectJSON(name); + expect(JSON.parse(stringifyActual(components))).eql(expectJSON); + expect(components).to.include.keys(__weex_bootstrap__.firstCall.args[0]); + + return actualStr; + } + + beforeEach(() => { + components = {}; + requireStub = sinon.stub(); + bootstrapStub = sinon.stub(); + + __weex_define__ = function(componentName, deps, factory) { + if (components[componentName]) { + throw new Error(`${componentName} is defined repeatly`); + } + + var __weex_require__ = requireStub; + var __weex_exports__ = {}; + var __weex_module__ = {exports : __weex_exports__} + + factory(__weex_require__, __weex_exports__, __weex_module__) + components[componentName] = __weex_module__.exports + } + + __weex_bootstrap__ = bootstrapStub; + + }); + + it('single template', () => { + expectActual('a'); + }); + + it('template with style', () => { + expectActual('b'); + }); + + it('template with style and script', () => { + expectActual('c'); + }); + + it('template with single inline element', () => { + expectActual('d'); + }); + + it('template with multiple inline elements', () => { + expectActual('e'); + }); + + it('parted files specifed in src', () => { + expectActual('f'); + }); + + it('component by requiring src and specifing alias', () => { + expectActual('g'); + expect(requireStub.callCount).eql(0); + }); + + it('component under same folder', () => { + expectActual('h'); + }); + + it('template with config and data', () => { + expectActual('i'); + expect(bootstrapStub.firstCall.args[1]).is.not.undefined; + expect(bootstrapStub.firstCall.args[2]).is.not.undefined; + }); + + it('template and use weex module', () => { + expectActual('j'); + expect(requireStub.callCount).eql(1); + expect(requireStub.firstCall.args).eql(['@weex-module/modal']); + }); + + it('template by using custom language', () => { + expectActual('k'); + expect(requireStub.callCount).eql(1); + expect(requireStub.firstCall.args).eql(['@weex-module/modal']); + }); + + it('template and require commonjs module', () => { + expectActual('l'); + expect(requireStub.callCount).eql(1); + expect(requireStub.firstCall.args).eql(['@weex-module/modal']); + }); + + it('template and use weex module in commonjs module', () => { + expectActual('m'); + expect(requireStub.callCount).eql(1); + expect(requireStub.firstCall.args).eql(['@weex-module/modal']); + }); + + it.skip('template with sourcemap', () => { + const actualStr = expectActual('n'); + const map = extractMap(actualStr); + const smc = new SourceMap.SourceMapConsumer(map); + + // new Array(276).fill(0).forEach((n, i) => { + // i = i + 1 + // const original = smc.originalPositionFor({ + // line: i, + // column: 0 + // }) + // if (original.source) { + // console.log(i, original.line, original.source) + // } + // }) + }); + + it('weex examples', () => { + expectActual('o'); + }); +}); diff --git a/test/webpack.config.js b/test/webpack.config.js new file mode 100644 index 0000000000000000000000000000000000000000..4f4d760e26d8f1d39576c811d69e70205d6b77d7 --- /dev/null +++ b/test/webpack.config.js @@ -0,0 +1,50 @@ +var path = require('path') +var cssnext = require('postcss-cssnext') + +var entry = {} +var start = 'a' +var end = 'o' +var count = end.charCodeAt(0) - start.charCodeAt(0) + +new Array(count + 1).fill(0) + .forEach((n, i) => { + var name = String.fromCharCode(i + start.charCodeAt(0)) + entry[name] = path.resolve(__dirname, 'spec', name + '.we?entry') + }) + +module.exports = { + entry: entry, + output: { + path: path.resolve(__dirname, 'actual'), + filename: '[name].js' + }, + devtool: 'source-map', + module: { + loaders: [ + { + test: /\.we(\?[^?]+)?$/, + loaders: [path.resolve(__dirname, '..', 'index.js')] + }, + { + test: /\.js/, + loaders: ['babel?presets[]=es2015'] + } + ] + }, + devtool: 'inline-source-map', + resolveLoader: { + modulesDirectories: ['./node_modules'] + }, + postcss: function() { + return [cssnext({ + browsers: ['last 1 version'] + })] + }, + weex: { + lang: { + cssnext: ['postcss'], + jade: ['jade-html'], + coffee: ['coffee'] + } + } +}