# karmeneo

> Karmeneo creates a RequireJS configuration of the Akeneo requirejs.yml files for running tests with Karma

Latest version **0.3.0** (published 2020-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install karmeneo
pnpm add karmeneo
yarn add karmeneo
bun add karmeneo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2020-03-09 |
| First published | 2020-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | Claudio Zizza |
| Maintainers | flagbird |
| Keywords | Akeneo, tests, test, karma |

## Links

- npm: https://www.npmjs.com/package/karmeneo
- Repository: git@github.com:flagbird/karmeneo
- npm.io page: https://npm.io/package/karmeneo

## Dependencies (9)

- [lodash](https://npm.io/package/lodash.md) ^3.2
- [yamljs](https://npm.io/package/yamljs.md) ^0.3
- [webpack](https://npm.io/package/webpack.md) ^4.29
- [deepmerge](https://npm.io/package/deepmerge.md) ^4.2.2
- [requirejs](https://npm.io/package/requirejs.md) ^2.3.6
- [@types/node](https://npm.io/package/@types/node.md) ^11.9
- [webpack-cli](https://npm.io/package/webpack-cli.md) ^3.2
- [requirejs-text](https://npm.io/package/requirejs-text.md) ^2.0.15
- [webpack-cleanup-plugin](https://npm.io/package/webpack-cleanup-plugin.md) ^0.5.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2020-03-09
- 0.2.0 — 2020-03-09
- 0.1.1 — 2020-03-04
- 0.1.0 — 2020-03-04

## README

# Karmeneo

Karmeneo creates a RequireJS configuration of the Akeneo requirejs.yml files for running tests
with Karma.

This is a WIP / PoC project. Use it on your own responsibility. It was tested on Akeneo 3.2.

## Why using this?

Creating RequireJS tests for Akeneo with karma are a mess when it comes to add all files to
the RequireJS config. Akeneo is using a bundle that enables the user to [add new RequireJS
files and templates with YAML](https://docs.akeneo.com/3.2/design_pim/overview.html#register-it).
To prevent changes in Akeneo AND your test config, Karmeneo will read the config files and
create a new RequireJS config with the new changes of the packages automatically and reduces
error sources and impediments during development.

## Installation

```
yarn add --dev karmeneo
```

## How does it work?

Currently the Akeneo requirejs.yml configs are going to be created when you run your tests with
karma. A file will be created that contains the RequireJS config for your tests.

``` javascript
const requireJsWriter = require('karmeneo');

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js');

// Karma configuration
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      { pattern: 'web/bundles/**/*.js', included: false },
      { pattern: 'tests/lib/**/*.js', included: false },

      // Add the created RequireJS config to Karma
      'tests/requirejs.config.js',
    ],
```

Use `require` to load Karmeneo and run the function `createRequireJsConfig` at the top of your
`karma.conf.js`. The argument of the function is the name and relative path where the RequireJS
config has to be saved. A new config file **won't be generated** if a file with that name exists.

Be sure to have added `web/bundles` to the pattern like in the example, because Karmeneo is using
the path to the files there.

### Additional packages

Not every RequireJS package is configured with Akeneo. But every other package can be added in the
configuration with `additionalLibs`:

``` javascript
const requireJsWriter = require('karmeneo');

const config = {
  additionalLibs: {
    'underscore': '../node_modules/underscore/underscore',
    'backbone': '../node_modules/backbone/backbone',
    'jquery': '../node_modules/jquery/dist/jquery',
  }
};

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js', config);

// Karma configuration
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      { pattern: 'web/bundles/**/*.js', included: false },
      { pattern: 'web/bundles/**/*.html', included: false },
      { pattern: 'tests/lib/**/*.js', included: false },
      { pattern: 'node_modules/*/*.js', included: false },
      { pattern: 'node_modules/jquery/dist/jquery.js', included: false },

      // Add the created RequireJS config to Karma
      'tests/requirejs.config.js',
    ],
```

### Use in Akeneo 4

Akeneo 4 introduces the changed directory structure of Symfony where the `web`-directory became
`public`. You can use the configuration key `isAkeneo4` and set it to true in that case:

``` javascript
const requireJsWriter = require('karmeneo');

const config = {
  isAkeneo4: true
};

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js', config);

// Karma configuration
module.exports = function(config) {
  config.set({
```

### Custom RequireJS config template

If the default config template file `config.temp` doesn't fit to your needs, you can create
your own config template and add the relative path to the configuration with `template`:

``` javascript
const requireJsWriter = require('karmeneo');

const config = {
  template: './tests/my-template.js'
};

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js', config);

// Karma configuration
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      { pattern: 'web/bundles/**/*.js', included: false },
      { pattern: 'web/bundles/**/*.html', included: false },
      { pattern: 'tests/lib/**/*.js', included: false },
      { pattern: 'node_modules/*/*.js', included: false },
      { pattern: 'node_modules/jquery/dist/jquery.js', included: false },
    
      // Add the created RequireJS config to Karma
      'tests/requirejs.config.js',
    ],
```

In the example the custom template's file name is `./tests/my-template.js` that is relative to the
project where you're executing the tests. lodash is used for the templating and has 
available variables for the packages that you'll have to use in your template:

#### requirejsFiles

The fetched file paths and ids of Akeneo and your custom ones as the AMD of RequireJS needs.

``` javascript
requirejs.config({

    paths: <%= requirejsFiles %>,
```

#### htmlAliasForText

Aliases used in `map` to handle Akeneo's HTML templates with the text! plugin.

``` javascript
    map: {
        '*': <%= htmlAliasForText %>,
    },
```

---
_Source: https://npm.io/package/karmeneo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
