Hey folks, has anyone manage to access static reso...
# javascript
s
Hey folks, has anyone manage to access static resources from the
jsTest
resources directory? No matter what I do I seem to just get a 404 It's a service worker so it needs to be accessible as a static file off the root path I've tried the following (with absolute path) but still getting a 404
Copy code
val devServer = (webpackConfig.devServer ?: KotlinWebpackConfig.DevServer())
                    webpackConfig.devServer = devServer.copy(
                        static = (devServer.static ?: mutableListOf()).apply {
                            add("<ABSOLUTE PATH>/>/src/jsTest/resources/")
                        }
                    )
t
Do you use/can use
per-file
compilation? If yes - you can write Worker in Kotlin and avoid this problem.
If no - additional configuration for tests resource tasks required AFAIK - it's known problem
Example of Worker in Kotlin you can find here
s
This may be a really obvious question @turansky but what is per-file compilation? I can't seem to find a good answer online?
t
It's Gradle option for Kotlin As result 1 kt file will be compiled in 1 js file
s
Ah okay thanks, not sure I want to resort to that but I'll have a play around with it Feels like quite a simple thing to want to do which is frustrating, thank you for your help though!
t
If you have/need lazy modules - it's very useful
s
The worker script is a generated one so I don't really want to port it to kotlin
t
Additional configuration for tests resource tasks required
AFAIK - it's known problem
s
Yeah looks to not be possible
t
Why?
s
You said it's a known problem? That seems to support what I'm seeing online
t
It's known problem, which you can fix locally
1. Find Gradle "test resources" task 2. Add additional folder for "sync" 3. SUCCESS
s
Ah okay I was trying to do it with webpack, I'll try that thanks!
t
It should be 3 lines in Gradle script
s
I'll have a go, the first script above I posted gets the file into the build folder but isn't served up by the server, but I'll try doing it directly from gradle
Turns out I was barking up the wrong tree. Leaving this here in case it helps someone. The file seems to be being copied correctly from the assets directory BUT the test server wasn't serving it up correctly. Adding this to the config fixed it
Copy code
js {
    browser {
        testTask {
            useKarma {
                // karma.config.d is a directory which contains karma.conf.js
                useConfigDirectory("<path to karma>/karma.config.d")
                useChromeHeadless()
            }
        }
        binaries.executable()
    }
}
Then
karma.conf.js
contains
Copy code
config.files.push({ pattern: '<root>/build/js/packages/lib-<lib name>-test/kotlin/mockServiceWorker.js', served: true, watched: false, included: false });
config.proxies['/mockServiceWorker.js'] = "/base/kotlin/mockServiceWorker.js";