Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CommonJS module imports in test fixtures #7

Open
OldSneerJaw opened this issue Mar 8, 2018 · 0 comments
Open

Support CommonJS module imports in test fixtures #7

OldSneerJaw opened this issue Mar 8, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@OldSneerJaw
Copy link
Owner

OldSneerJaw commented Mar 8, 2018

Feature Request

Description

The CouchDB JavaScript design functions API includes specialized support for CommonJS module imports. While there is nothing to stop one from using couchster to generate a validation function from document definitions that include the require statement in custom code as is, any attempt to exercise code that depends on a required module with a couchster test fixture will fail since its test fixtures do not support CommonJS module imports.

Add support for importing CommonJS modules that conforms to the constraints outlined in the CouchDB documentation. Notably, module paths are "relative to the design document’s views object, but modules can only be loaded from the object referenced via lib". In other words, a CommonJS module file must be defined at the path views/lib relative to the current working directory to properly simulate the environment in which they will be deployed to a CouchDB design document.

In the meantime, the preferred approach for modularization is via the importDocumentDefinitionFragment macro as documented in the couchster README.

Examples

A valid module import, assuming that a CommonJS module string has been defined in the document at views.lib.time:

var time = require('views/lib/time');

Note that CouchDB does not seem to allow a dot (.) to indicate the current "directory"/path. For example, this is invalid:

var time = require('./views/lib/time');
@OldSneerJaw OldSneerJaw added the enhancement New feature or request label Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant