I've started using the intern library to write functional tests in js, and I realized that I couldn't understand this syntax:
var assert = require('intern/chai!assert');
var registerSuite = require('intern!object');
What is the purpose of the !
character in the argument of the require()
method?
@gocanto npm packages can have a “scope”, which is a prefix beginning with the @ symbol. It's just a way of name-spacing npm packages.
Scoped packages in npm are preceded by an '@' symbol. A scope allows you to create a package with the same name as a package created by another user or Org without conflict.
Short answer
It identifies a resource that is part of a plugin.
The structure of the identifier is: [plugin]![resource]
.
Long answer
In the documentation, you can find that:
Intern is built on top of a standard amd loader, which means that its modules are also normally written in the AMD module format.
That's why and how the require
function is actually injected, so it's clear that you are not using the require
module provided along with Node.JS.
It states also that:
[AMD format] Allows modules and other assets to be asynchronously or conditionally resolved by writing simple loader plugins
If you follow the link provided with the documentation when it cites the loaders, you find that:
Loader plugins extend an AMD implementation by allowing loading of resources that are not traditional JavaScript dependencies.
In particular, you can find that a dependency has the following form:
[Plugin Module ID]![resource ID]
It goes without saying that the default implementation of the loader you get by using intern adheres to the above mentioned standard.
That said, it follows that, if we consider:
intern/chai!assert
You can read it as inter/chai
as plugin module and assert
as actually required resource.
The purpose of the ! character in the argument of the require()
method is to satisfy the requirements of the syntax used to identify a resource that is itself part of a plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With