Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Loading local files #34

Open
talltyler opened this issue Oct 4, 2017 · 6 comments
Open

Loading local files #34

talltyler opened this issue Oct 4, 2017 · 6 comments

Comments

@talltyler
Copy link

When Puppeteer is started there are a number of dependencies that are loaded into the browsers window but these are all hard coded from what I can see. Is there a way to give tests access to local files that can be loaded into tests?

@ctdio
Copy link
Owner

ctdio commented Oct 4, 2017

Hello @talltyler, this module uses lasso underneath the hood. So you can just require in any modules that you need within your tests.

Ex:

const someModule = require('../path/to/module/relative/to/test/file')

describe('test', () => {
  // etc...
})

If you need to add additional dependencies that are not commonjs modules, for example dist version of jquery, you can add that by providing the lassoDependencies in a .mocha-puppeteer-config.js file.

Ex:

module.exports = {
  lassoDependencies: [
    'path/to/dist/jquery.js'
  ]
}

Dependencies given as the lassoDependencies are loaded in before tests are run, so you will have access to them during tests. Hope this helps!

@talltyler
Copy link
Author

talltyler commented Oct 4, 2017

Sorry I wasn't clear. I'm not talking about modules or libraries of code. I'm talking about ajax style loading of static files, like images, text files and so on from within my tests. I can load these files from external urls but I would like to load a file related to the test that I am writing. Other test runners have the ability to specify a path of files that can be later loaded from the local port that is created when the tests run. Is there a way to do this?

@ctdio
Copy link
Owner

ctdio commented Oct 5, 2017

Ah I see. Sorry but at the moment this is not a feature that is supported. This would be very useful feature to have though. Any ideas on what you think the best api for this would look like? cc @austinkelleher

@talltyler
Copy link
Author

Just a path in the config would work. Then from a tests it would be cool if urls could load from either file:// or from localhost from a port configurable from the config again.

@austinkelleher
Copy link
Collaborator

I agree that this is a feature that we should implement. @talltyler any interest in working on this?

@talltyler
Copy link
Author

I never had a chance to pick this up, it would be great is someone else had the time to do it. Sorry.

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

No branches or pull requests

3 participants