antonmedv / monkberry

Monkberry is a JavaScript library for building web user interfaces
https://monkberry.js.org
MIT License
1.49k stars 78 forks source link

Integration tests #56

Open PabloKowalczyk opened 5 years ago

PabloKowalczyk commented 5 years ago

Hello, how to write integration tests for components? Some examples in the documentation would be very helpful. Thanks :)

antonmedv commented 5 years ago

You can use something like jsdom

PabloKowalczyk commented 5 years ago

I'm trying to configure Mocha with Webpack, but something is failing when i do import Btn from 'App/components/btn';. IDK this is the Monkberry or Mocha error. Call stack:

 RUNTIME EXCEPTION  Exception occurred while loading your tests

TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (<anonymous>)
    at Object../assets/cs-app/js/templates/btn.monk (/vagrant/.tmp/mocha-webpack/1540640188825/bundle.js:164:24)
    at __webpack_require__ (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/webpack/bootstrap 15cae6e813f8c27b9512:19:1)
    at Object../assets/cs-app/js/components/btn.js (/vagrant/.tmp/mocha-webpack/1540640188825/bundle.js:78:89)
    at __webpack_require__ (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/webpack/bootstrap 15cae6e813f8c27b9512:19:1)
    at Object.require (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/assets/cs-app/test/some.js:5:1)
    at __webpack_require__ (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/webpack/bootstrap 15cae6e813f8c27b9512:19:1)
    at run (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/node_modules/mocha-webpack/lib/entry.js:3:20)
    at Array.forEach (<anonymous>)
    at Object../node_modules/mocha-webpack/lib/entry.js (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/node_modules/mocha-webpack/lib/entry.js:10:1)
    at __webpack_require__ (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/webpack/bootstrap 15cae6e813f8c27b9512:19:1)
    at ./assets/cs-app/js/components/btn.js.Object.defineProperty.value (/vagrant/.tmp/mocha-webpack/1540640188825/webpack:/webpack/bootstrap 15cae6e813f8c27b9512:62:1)
    at Object.<anonymous> (/vagrant/.tmp/mocha-webpack/1540640188825/bundle.js:66:10)
    at Module._compile (module.js:653:30)
    at Object._module2.default._extensions.(anonymous function) [as .js] (/vagrant/node_modules/mocha-webpack/lib/util/registerRequireHook.js:147:12)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at /vagrant/node_modules/mocha/lib/mocha.js:250:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/vagrant/node_modules/mocha/lib/mocha.js:247:14)
    at Mocha.run (/vagrant/node_modules/mocha/lib/mocha.js:576:10)
    at /vagrant/node_modules/mocha-webpack/lib/runner/TestRunner.js:196:25
    at Compiler.<anonymous> (/vagrant/node_modules/mocha-webpack/lib/webpack/compiler/registerReadyCallback.js:26:7)
    at Compiler.applyPlugins (/vagrant/node_modules/tapable/lib/Tapable.js:61:14)
    at emitRecords.err (/vagrant/node_modules/webpack/lib/Compiler.js:264:11)
    at Compiler.emitRecords (/vagrant/node_modules/webpack/lib/Compiler.js:371:38)
    at emitAssets.err (/vagrant/node_modules/webpack/lib/Compiler.js:258:10)
    at applyPluginsAsyncSeries1.err (/vagrant/node_modules/webpack/lib/Compiler.js:364:12)
    at next (/vagrant/node_modules/tapable/lib/Tapable.js:218:11)
    at Compiler.compiler.plugin (/vagrant/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at Compiler.applyPluginsAsyncSeries1 (/vagrant/node_modules/tapable/lib/Tapable.js:222:13)
    at Compiler.afterEmit (/vagrant/node_modules/webpack/lib/Compiler.js:361:9)
    at require.forEach.err (/vagrant/node_modules/webpack/lib/Compiler.js:350:15)
    at /vagrant/node_modules/async/dist/async.js:473:16
    at iteratorCallback (/vagrant/node_modules/async/dist/async.js:1064:13)
    at /vagrant/node_modules/async/dist/async.js:969:16
    at MemoryFileSystem.writeFile (/vagrant/node_modules/memory-fs/lib/MemoryFileSystem.js:328:9)
    at writeOut (/vagrant/node_modules/webpack/lib/Compiler.js:339:28)
    at require.forEach (/vagrant/node_modules/webpack/lib/Compiler.js:345:12)
    at /vagrant/node_modules/async/dist/async.js:3110:16
    at eachOfArrayLike (/vagrant/node_modules/async/dist/async.js:1069:9)
    at eachOf (/vagrant/node_modules/async/dist/async.js:1117:5)
    at Object.eachLimit (/vagrant/node_modules/async/dist/async.js:3172:5)
    at emitFiles (/vagrant/node_modules/webpack/lib/Compiler.js:315:21)
    at Immediate.<anonymous> (/vagrant/node_modules/memory-fs/lib/MemoryFileSystem.js:288:4)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)
antonmedv commented 5 years ago

Check if your loaders is on.

PabloKowalczyk commented 5 years ago

Seems they are, SCSS loader works as expected. Requiring plain JS also works, but if any file import *.monk template then it starts to fail. My module config:

[ { test: /\.jsx?$/,
       exclude: /(node_modules|bower_components)/,
       use: [Array] },
     { test: /\.css$/, use: [Array] },
     { test: /\.(png|jpg|jpeg|gif|ico|svg|webp)$/,
       loader: 'file-loader',
       options: [Object] },
     { test: /\.(woff|woff2|ttf|eot|otf)$/,
       loader: 'file-loader',
       options: [Object] },
     { test: /\.s[ac]ss$/, use: [Array] },
     { test: /bootstrap\.native/,
       loader: 'bootstrap.native-loader',
       options: [Object] },
     { test: /\.monk$/, loader: 'monkberry-loader' } ] }

EDIT After some investigation i found out where the problem is. In generated output file for test there is a line btn.prototype = Object.create(Monkberry.prototype);, for some reason Monkberry.prototype is undefined. As a side note, Webpack's target is node, not web. I was trying to debug it with console.log(Monkberry); but the output { Compiler: [Function: Compiler] } tells me nothing. Hope this will help you to find problem.

PabloKowalczyk commented 5 years ago

Hey, any progress with this issue? Maybe repo with bug will be helpful?

antonmedv commented 5 years ago

Sorry, haven’t time for this repo now.