Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Support full JS in test scripts #101

Open
tpluscode opened this issue Jun 1, 2022 · 7 comments
Open

Support full JS in test scripts #101

tpluscode opened this issue Jun 1, 2022 · 7 comments

Comments

@tpluscode
Copy link

tpluscode commented Jun 1, 2022

Without being able to reuse existing JS packages and reuse test scripts, the tests will quickly become very repetitive. I would like to write a test using anything node has at its disposal.

// test.js
import { parse } from 'some-npm-package'
import { responseOk } from './test-helper.js'

// is async supported by the way?
client.test('rich test', async () => {
  const parsed = await parse(response.body)

  client.test(parsed.something.length === 101, 'Incorrect number of results')
})

// reuse assertion function in many tests
client.test('Response is 200', responseOk)

The test-helper.js script could be something like

// because I do not want to repeat that assertion
export function responseOk(client, response) {
    client.assert(response.status === 200, 'Response was not successful')
}

This way would be possible to write more concise and idiomatic tests


Currently, when I tried import or require the script does not even parse and throws an error

:1:0 Expected an operand but found const
const $rdf = require('rdf-ext')
^ in at line number 1 at column number 0

Here's a GraalVM example, which might be helpful. Rather than a simple eval, a context is created which should allow importing scripts and package. The latter is not show as example but implied on the linked page

@quangson91
Copy link
Collaborator

@tpluscode
Thank you for the feedback.
Let me try to implement a javascript Context .
If you have any experience with GraalVM Javascript context, the PR is welcome!

@tpluscode
Copy link
Author

I honestly don't have the faintest clue about it 😅

@quangson91
Copy link
Collaborator

@tpluscode
I will try to implement it this weekend.
Thank you!

@tpluscode
Copy link
Author

Here's another example. In my test I wrote

client.test("Created sortBy:title properties", function() {
  const {bindings} = JSON.parse(response.body).results
  const total = bindings[0].total.value

  client.assert(total == 0, `${total} records found without sort title`);
});

But it also fails with the Expected an operand but found const error. The scripting support appears super limited right now

@quangson91
Copy link
Collaborator

@tpluscode
I got it.
Thank you for sharing more detail.

@bravenoob
Copy link

Great feature request.

@konikvranik
Copy link
Contributor

konikvranik commented Nov 19, 2022

@quangson91

Hello, any progress on this project, or is it already dead?

does anybody know another alternative to run the Jetbrains http request files from commandline with support for the latest features and no bugs?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants