or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-mocha-webpack

A test runner that combines Mocha testing framework with webpack bundling capabilities for modern JavaScript applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/mocha-webpack@1.1.x

To install, run

npx @tessl/cli install tessl/npm-mocha-webpack@1.1.0

0

# Mocha Webpack

1

2

Mocha Webpack is a test runner that combines the power of the Mocha testing framework with webpack's module bundling capabilities. It serves as a wrapper around webpack and mocha, automatically precompiling test files with webpack before executing them with mocha.

3

4

## Package Information

5

6

- **Package Name**: mocha-webpack

7

- **Package Type**: npm

8

- **Language**: JavaScript (ES6/Flow types)

9

- **Installation**: `npm install webpack mocha mocha-webpack --save-dev`

10

11

## Core Imports

12

13

```javascript

14

const createMochaWebpack = require('mocha-webpack');

15

```

16

17

For ES6 modules (using Babel transpiled src):

18

19

```javascript

20

import createMochaWebpack from 'mocha-webpack/src/createMochaWebpack';

21

import MochaWebpack from 'mocha-webpack/src/MochaWebpack';

22

```

23

24

## Basic Usage

25

26

```javascript

27

const createMochaWebpack = require('mocha-webpack');

28

29

const mochaWebpack = createMochaWebpack();

30

31

mochaWebpack

32

.addEntry('./test/**/*.test.js')

33

.webpackConfig(require('./webpack.config.js'))

34

.reporter('spec')

35

.run()

36

.then((failures) => {

37

process.exit(failures);

38

})

39

.catch((err) => {

40

console.error(err);

41

process.exit(1);

42

});

43

```

44

45

## Architecture

46

47

Mocha Webpack is built around several key components:

48

49

- **MochaWebpack Class**: Fluent API for configuring and running tests programmatically

50

- **CLI Interface**: Command-line tool with extensive options matching mocha's interface

51

- **Test Runner**: Internal engine that coordinates webpack compilation and mocha execution

52

- **Watch Mode**: Intelligent file watching that analyzes dependency graphs to run only affected tests

53

- **Memory Compilation**: Webpack builds are kept in memory for better performance without writing files to disk

54

55

## Capabilities

56

57

### Programmatic API

58

59

Factory function and fluent MochaWebpack class for programmatic test configuration and execution.

60

61

```javascript { .api }

62

/**

63

* Creates a new MochaWebpack instance

64

* @returns {MochaWebpack} New MochaWebpack instance

65

*/

66

function createMochaWebpack(): MochaWebpack;

67

68

class MochaWebpack {

69

addEntry(file: string): MochaWebpack;

70

addInclude(file: string): MochaWebpack;

71

webpackConfig(config: object): MochaWebpack;

72

run(): Promise<number>;

73

watch(): Promise<void>;

74

}

75

```

76

77

[Programmatic API](./programmatic-api.md)

78

79

### Command Line Interface

80

81

Complete CLI with extensive options for running tests from the command line, including watch mode and webpack configuration.

82

83

```bash { .api }

84

# Basic usage

85

mocha-webpack [options] [files...]

86

87

# Common options

88

--watch, -w # Watch files for changes

89

--webpack-config # Path to webpack config

90

--reporter, -R # Test reporter

91

--grep, -g # Only run tests matching pattern

92

```

93

94

[Command Line Interface](./cli.md)

95

96

## Types

97

98

```javascript { .api }

99

/**

100

* Configuration options for MochaWebpack instance

101

*/

102

interface MochaWebpackOptions {

103

cwd: string;

104

webpackConfig: object;

105

bail: boolean;

106

reporter: string | Function;

107

reporterOptions: object;

108

ui: string;

109

fgrep?: string;

110

grep?: string | RegExp;

111

invert: boolean;

112

ignoreLeaks: boolean;

113

fullStackTrace: boolean;

114

colors?: boolean;

115

useInlineDiffs: boolean;

116

timeout: number;

117

retries?: number;

118

slow: number;

119

asyncOnly: boolean;

120

delay: boolean;

121

interactive: boolean;

122

quiet: boolean;

123

growl?: boolean;

124

}

125

```