2

Suppose I would like to test a javascript function, which processes strings, with QUnitin browser. Now I would like to read the input strings from files.

I guess I cannot use node.js modules to access the file system. I am thinking about calling the browser from the javascript to read a file by URL (file:/home/...)

Does it make sense? How would you suggest do it?

3 Answers 3

2

You might want to have a look at the File and FileReader APIs. They allow access to locally stored files.

You could also consider using JSONP to retrieve your test data from a remote host. You would need network access to that host though whenever you want to run your tests.

Sign up to request clarification or add additional context in comments.

Comments

1

In my eyes you have two options to do this :

  1. Using pure Ajax to read the content of a file url (btw I'd never tried it before)
  2. Using a webserver there is running a language that supports reading file content and send it as an http response. Use Ajax to retrive and store that response.

Comments

1

"file:/home/" will only work if you open a local html file into your browser due to browser's Same Origin Policy restriction.

If you want to follow standards, you have to host such file on same server that the html that contains the js function to test, and load it trough an ajax request. It will be available as a plain string in your JS context.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.