if you compile all your tests to a directory and t...
# javascript
j
if you compile all your tests to a directory and then run karma or node by itself over them?
n
Attempting to use an alternative method for testing by just using the Karma Gradle plugin but encountered a JS syntax error:
Copy code
> Task :js:karmaRun FAILED
/home/napperley/idea_projects/webscene/webscene-core/js/node_modules/karma/node_modules/log4js/lib/layouts.js:69
  ) + util.format(...loggingEvent.data);
                  ^^^

SyntaxError: Unexpected token ...
Specifying the Node module dependencies (in the build file) doesn't resolve the error:
Copy code
configure<KarmaModuleExtension> {
    val libDir = "$buildDir/lib"
    val compileOutput = compileKotlin2Js.outputFile
    val testOutput = compileTestKotlin2Js.outputFile

    dependencies(mutableListOf("log4js@v3.0.5", "mocha@v5.2.0"))
    frameworks = mutableListOf("mocha")
    browsers = mutableListOf("PhantomJS")
    files("$libDir/kotlin.js", "$libDir/*.js", "$compileOutput", "$testOutput")
}
j
no es6 available?
... spread operator in js was only node6 I think
n
The Karma plugin appears to be using Node v4.2.3.
j
nope, node 5 was when it became available apparently
so yeah, if the karma plugin is using node 4, then what it's trying to do won't work
you might need to postprocess your js output with babel
unless kotlin-js supports setting a target like es5
n
Is there no way to handle JS post processing via Gradle?
j
I thought you could use babel, but I'm not sure tbh
n
Doesn't Kotlin JS transpile to ES 5 by default?
j
no idea. if it's outputting code with
...
then definitely not
oh, sorry, just saw the source of the error 😞
so karma itself has code that isn't es5 compatible
in which case, you either need to bundle the entire suite and transpile, or use a lower version of karma, or use a higher version of node, I think
n
The Karma plugin depends on the Node plugin.
j
hmm, I'm not sure then. other than updating the node plugin I wouldn't know where to look
n
Updating the node version works with the following:
Copy code
import com.moowork.gradle.node.NodeExtension

configure<NodeExtension> {
    version = "8.11.4"
}
j
awesome! so that makes the karma thing work too?
n
Not sure since this error appears in the output:
Copy code
PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.041 secs / 0 secs)
😕
j
argh
is there a verbose flag?
n
No, not one that can be found in the Karma plugin docs 🙁.
Switched to Chrome instead of PhantomJS and can briefly see a Chrome window containing a green banner for about 2 sec before it disappears, after running the tests. End up with a similar error:
Copy code
Chrome 67.0.3396 (Linux 0.0.0): Executed 0 of 0 ERROR (0.002 secs / 0 secs)
j
hmm, I wonder if it just can't find any tests to run then.
n
Gradle build structure from the Kotlin JS sub project, which is part of a Kotlin multi-platform project.
Contents of karma.conf.js file:
Copy code
module.exports = function (config) {
    config.set({
        frameworks: ['mocha', 'chai', 'commonjs'],
        reporters: ['progress'],
        files: [
            'build/classes/kotlin/test/*.js',
            'build/node_modules/*.js'
        ],
        // Karma web server port.
        port: 9876,
        exclude: [],
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        browsers: ['ChromeHeadless'],
        preprocessors: {
            '**/*.js': ['commonjs']
        },
        concurrency: Infinity
    })
};
j
what's the contents of one of the files in build/classes/kotlin/test/ ?
n
Contents of one of the files in build/classes/kotlin/test.
j
Is that the structure that Karma expects? Because it doesn't look like something that is discoverable as a test suite to me
n
The contents of the file ☝️ are the result of transpiling a kt file (containing a basic unit test) to js. If Karma can't detect the test suite then it is a Kotlin JS issue, or Karma hasn't been configured properly.
Contents of original file that is transpiled to JS. Currently contains a dummy test that will be replaced with real tests.
j
to debug, try run karma directly pointing it at that file with the kotlin and kotlin-test things set up globally. otherwise it might be at the "open an issue on the tracker" point 😞
n
This is the project where the testing takes place: https://gitlab.com/webscene/webscene-core/tree/testing . Hopefully a Kotlin JS team member can have a look and see if anything is missing (or needs changing) otherwise I "might" have encountered a Kotlin JS issue. With the project run the following to execute the tests:
./gradlew :js:test