C3 AI Documentation Home

Es.Package

Es.Package

Es.Package provides tooling to run build, bundle and test an ECMAScript package in an unnoticeable way.

This means packages that follow a normal NPM package lifecycle can be authored without requiring a C3 Server running but once their containing C3 package runs through Jarvis CI, they will be built, bundled and tested.

It is advisable to not have any packages depending on a package containing an Es.Package and instead release the NPM package for direct consumption.

How to use?

  1. Move your NPM or Bun package into a resource folder
  2. Create your Es.Package metadata instance
  3. Configure the Es.Package as needed
  4. Create a js-rhino test that calls Js.PackageTester.testPkg(PKG_ID)

Resource folder

As an example, for a package named myPkg, the convention is to have $C3PKG/resource/myPkg, but you can decide the name of your folder when creating the Es.Package metadata.

Es.Package metadata

Create a file $C3PKG/metadata/Es.Package/$PKG_ID.json with the following contents:

JSON
{
  "id": "myPkg",
  /**
   * Uncomment and adjust if you want to change the default path
   */
  // resourcePath: "resource/myPkg",
  /**
   * Uncomment and adjust if your testScript is not called "test"
   */
  // testScript: "test",
  /**
   * Uncoment and adjust if your test script with coverage is different
   */
  // coverageScript: "test:coverage",
}

Running tests

Create a test file $C3PKG/test/js-rhino/test_myPkg.js with the following contents:

JavaScript
Es.PackageTester.testEsPackage(Es.Package.forId('myPkg'));
Was this page helpful?