-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweaks to test form handling, working except for 'fewer inputs'
- Loading branch information
1 parent
6bbf5e9
commit 2f907e4
Showing
4 changed files
with
97 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
runTest as runBrowserTest, | ||
type TestInput, | ||
type TestOutput, | ||
} from "@regexplanet/common"; | ||
|
||
export async function runTestPage( | ||
test_url: string, | ||
testInput: TestInput | ||
): Promise<TestOutput> { | ||
console.log("running test", testInput); | ||
if (!testInput || !testInput.regex) { | ||
return { | ||
success: false, | ||
message: "Please enter a regular expression to test", | ||
}; | ||
} | ||
|
||
if (test_url === "javascript:runBrowserTest") { | ||
return runBrowserTest(testInput); | ||
} | ||
|
||
const postData = | ||
`regex=${encodeURIComponent(testInput.regex)}` + | ||
`&replacement=${encodeURIComponent(testInput.replacement)}` + | ||
`&${testInput.options | ||
.map((option) => `option=${encodeURIComponent(option)}`) | ||
.join("&")}` + | ||
`&${testInput.inputs | ||
.map((input) => `input=${encodeURIComponent(input)}`) | ||
.join("&")}`; | ||
|
||
//console.log("posting", test_url, postData); | ||
|
||
const response = await fetch(test_url, { | ||
method: "POST", | ||
body: postData, | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
//mode: "no-cors", | ||
}); | ||
//console.log("response", response); | ||
const data = await response.json(); | ||
|
||
console.log("test results", data); | ||
|
||
return data as TestOutput; | ||
} |