Skip to content

Commit 322f5bd

Browse files
committed
✅ add qs-kotlin vs qs.js compatibility tests
1 parent d299b07 commit 322f5bd

File tree

11 files changed

+900
-3
lines changed

11 files changed

+900
-3
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ allprojects {
1616
}
1717

1818
subprojects {
19-
plugins.withId("org.jetbrains.kotlin.jvm") { apply(plugin = "org.jetbrains.dokka") }
20-
plugins.withId("org.jetbrains.kotlin.android") { apply(plugin = "org.jetbrains.dokka") }
19+
if (name in listOf("qs-kotlin", "qs-kotlin-android")) {
20+
plugins.withId("org.jetbrains.kotlin.jvm") { apply(plugin = "org.jetbrains.dokka") }
21+
plugins.withId("org.jetbrains.kotlin.android") { apply(plugin = "org.jetbrains.dokka") }
22+
}
2123
}
2224

2325
nexusPublishing {

comparison/build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
plugins {
2+
kotlin("jvm")
3+
application
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
implementation(project(":qs-kotlin"))
10+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
11+
}
12+
13+
application { mainClass.set("io.github.techouse.qskotlin.compare.MainKt") }
14+
15+
tasks
16+
.matching { t ->
17+
t.name.startsWith("publish", ignoreCase = true) ||
18+
t.name.startsWith("sign", ignoreCase = true) ||
19+
t.name.startsWith("dokka", ignoreCase = true)
20+
}
21+
.configureEach { enabled = false }

comparison/compare_outputs.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Get the directory of the script
4+
script_dir=$(dirname "$0")
5+
6+
# Run the JavaScript and Dart scripts and save their outputs
7+
node_output=$(node "$script_dir/js/qs.js")
8+
kt_output=$(../gradlew -q :comparison:run --console=plain --warning-mode=none)
9+
10+
# Compare the outputs
11+
if [ "$node_output" == "$kt_output" ]; then
12+
echo "The outputs are identical."
13+
exit 0
14+
else
15+
echo "The outputs are different."
16+
echo "Differences:"
17+
diff <(echo "$node_output") <(echo "$kt_output")
18+
exit 1
19+
fi

comparison/js/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

comparison/js/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "qs_comparison",
3+
"version": "1.0.0",
4+
"description": "A comparison of query string parsing libraries",
5+
"author": "Klemen Tusar",
6+
"license": "BSD-3-Clause",
7+
"dependencies": {
8+
"qs": "^6.14.0"
9+
}
10+
}

comparison/js/qs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const qs = require('qs');
4+
5+
// Use path.join to combine __dirname with the relative path to test_cases.json
6+
const filePath = path.join(__dirname, 'test_cases.json');
7+
const e2eTestCases = JSON.parse(fs.readFileSync(filePath).toString());
8+
9+
e2eTestCases.forEach(testCase => {
10+
console.log('Encoded:', qs.stringify(testCase.data));
11+
console.log('Decoded:', JSON.stringify(qs.parse(testCase.encoded)));
12+
});

0 commit comments

Comments
 (0)