Skip to content

Commit

Permalink
fix packing test-resources for library js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Aug 16, 2023
1 parent e1454b9 commit fbcfd59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
35 changes: 35 additions & 0 deletions gradle/pack-library-test-resources.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
val rootProjectAbsPath = rootProject.projectDir.absolutePath
val path = """"$rootProjectAbsPath/library/build/generated/moko/jsMain/iomichaelrockslibphonenumber/res""""
val webpackConfig = File(projectDir, "webpack.config.d/pack-library-resources-generated.js")

fun createWebpackConfig() {
val configText = """const path = require('path');
const mokoResourcePath = path.resolve($path);
config.module.rules.push({
test: /(ShortNumberMetadataProto_|PhoneNumberMetadataProto_|PhoneNumberMetadataProtoForTesting_|PhoneNumberAlternateFormatsProto_)[^.]+${'$'}/,
include: [
path.resolve(mokoResourcePath, "files"),
],
type: 'asset/inline',
generator: {
dataUrl: content => {
// Convert buffer content to base64 and prepend it with mimetype
return `${'$'}{content.toString('base64')}`
}
}
});"""
webpackConfig.writeText(configText)
}

tasks.create("createPackResourcesWebpackConfig") {
// Define the task's output
outputs.file(webpackConfig)

doFirst {
createWebpackConfig()
}
}

tasks.getByName("compileKotlinJs").dependsOn("createPackResourcesWebpackConfig")
4 changes: 3 additions & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ kotlin {
}
val jvmCommonTest by creating {
dependsOn(commonTest)
dependencies{
dependencies {
implementation(libs.junit)
implementation(libs.mockito.core)
}
Expand Down Expand Up @@ -215,3 +215,5 @@ afterEvaluate {
}
}
*/

apply(from = "$rootDir/gradle/pack-library-test-resources.gradle.kts")

0 comments on commit fbcfd59

Please sign in to comment.