Skip to content

Commit

Permalink
docs: document how to load files from another server (#3622)
Browse files Browse the repository at this point in the history
Fixes #1486
  • Loading branch information
devoto13 committed Jan 20, 2021
1 parent 3653caf commit 07edde4
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions docs/config/02-files.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
**The `files` array determines which files are included in the browser and which files are watched and served by Karma.**
The `files` array determines which files are included in the browser, watched, and served by Karma.


## Pattern matching and `basePath`
- All of the relative patterns will get resolved using the `basePath` first.
- If the `basePath` is a relative path, it gets resolved to the
directory where the configuration file is located.
- Eventually, all the patterns will get resolved into files using
[glob], so you can use [minimatch] expressions like `test/unit/**/*.spec.js`.


## Ordering
- The order of patterns determines the order in which files are included in the browser.
- Multiple files matching a single pattern are sorted alphabetically.
- Each file is included exactly once. If multiple patterns match the
same file, it's included as if it only matched the first pattern.


## Included, served, watched
Each pattern is either a simple string or an object with the following properties:
## `files`
**Type.** Array
**No Default.** This property is mandatory.
**Description.** Each item is either a string (equivalent to `{ pattern: "<string>" }`) or an object with the following properties:

### `pattern`
* **Type.** String
* **No Default.** This property is mandatory.
* **Description.** The pattern to use for matching.
* **Description.** The pattern to use for matching. See below for details on how patterns are resolved.

### `type`
* **Type.** String
Expand Down Expand Up @@ -68,6 +54,18 @@ Each pattern is either a simple string or an object with the following propertie
* **Default.** `false`
* **Description.** Should the files be served from disk on each request by Karma's webserver?

## Pattern matching and `basePath`
- All of the relative patterns will get resolved using the `basePath` first.
- If the `basePath` is a relative path, it gets resolved to the
directory where the configuration file is located.
- Eventually, all the patterns will get resolved into files using
[glob], so you can use [minimatch] expressions like `test/unit/**/*.spec.js`.

## Ordering
- The order of patterns determines the order in which files are included in the browser.
- Multiple files matching a single pattern are sorted alphabetically.
- Each file is included exactly once. If multiple patterns match the
same file, it's included as if it only matched the first pattern.

## Preprocessor transformations
Depending on preprocessor configuration, be aware that files loaded may be transformed and no longer available in
Expand Down Expand Up @@ -100,6 +98,30 @@ files: [
],
```

## Loading files from another server

Pattern can also be an absolute URL. This allows including files which are not served by Karma.

Example:

```javascript
config.set({
files: [
'https://example.com/my-lib.js',
{ pattern: 'https://example.com/my-lib', type: 'js' }
]
})
```

Absolute URLs have some special rules comparing to the regular file paths:

- Globing is not support, so each URL must be specified as a separate pattern.
- Most of the regular options are not supported:
- `watched` is always `false`
- `included` is always `true`
- `served` is always `false`
- `nocache` is always `false`

## Loading Assets
By default all assets are served at `http://localhost:[PORT]/base/`

Expand Down

0 comments on commit 07edde4

Please sign in to comment.