---
slug: /quickstart/947391/test
displayed_sidebar: "quickstart"
hide_table_of_contents: true
title: "Test the application"
---

# Quickstart

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import QuickstartDoc from '@site/src/components/quickstartDoc.js'
import Embed from '@site/src/components/embed.js'

export const ids = {
    Go: "v676qm2pxae",
    "Node.js": "Wb_vszr9Ule",
    Python: "yZj9P2N03-D"
}

<QuickstartDoc embeds={ids}>

## Test the application

The pipeline in the previous example was illustrative - you wouldn't ever use it in the real world! So let's write a Dagger pipeline to do something more useful, like running an application's tests.

The code listing below demonstrates a Dagger pipeline that runs tests for the example application, by executing the `npm run test` command.

:::tip
The `npm run test` command is appropriate for a React application, but other applications are likely to use different commands. Modify your Dagger pipeline accordingly.
:::

<Tabs groupId="language" className="embeds">
<TabItem value="Go">

<Embed id="v676qm2pxae" />

This code listing does the following:

- It creates a Dagger client with `Connect()` as before.
- It uses the client's `Container().From()` method to initialize a new container from a base image - again, the `node:16-slim` image. This base image is the Node.js version to use for testing. The `From()` method returns a new `Container` object with the result.
- It uses the `Container.WithDirectory()` method to mount the source code directory on the host at the `/src` mount point in the container, and the `Container.WithWorkdir()` method to set the working directory to that mount point.
  - Notice that the `Container.WithDirectory()` method accepts additional options to exclude (or include) specific files from the mount. In this case, it excludes the `node_modules` (locally-installed dependencies), `ci` (pipeline code) and `build` (build artifacts) directories.
- It uses the `Container.WithExec()` method to define the commands to install dependencies and run tests in the container - in this case, the commands `npm install` and `npm test -- --watchAll=false`.
- It uses the `Container.Stderr()` method to return the error stream of the last executed command. No error output implies successful execution (all tests pass).
  - Failure, indicated by error output, will cause the pipeline to terminate.

Run the pipeline by executing the command below from the application directory:

```shell
dagger run go run ci/main.go
```

:::tip
The `From()`, `WithDirectory()`, `WithWorkdir()` and `WithExec()` methods all return a `Container`, making it easy to chain method calls together and create a pipeline that is intuitive to understand.
:::

</TabItem>
<TabItem value="Node.js">

<Embed id="Wb_vszr9Ule" />

This code listing does the following:

- It creates a Dagger client with `connect()` as before.
- It uses the client's `container().from()` method to initialize a new container from a base image - again, the `node:16-slim` image. This base image is the Node.js version to use for testing. The `from()` method returns a new `Container` object with the result.
- It uses the `Container.withDirectory()` method to mount the source code directory on the host at the `/src` mount point in the container, and the `Container.withWorkdir()` method to set the working directory to that mount point.
  - Notice that the `Container.withDirectory()` method accepts additional options to exclude (or include) specific files from the mount. In this case, it excludes the `node_modules` (locally-installed dependencies), `ci` (pipeline code) and `build` (build artifacts) directories.
- It uses the `Container.withExec()` method to define the commands to install dependencies and run tests in the container - in this case, the commands `npm install` and `npm test -- --watchAll=false`.
- It uses the `Container.stderr()` method to return the error stream of the last executed command. No error output implies successful execution (all tests pass).
  - Failure, indicated by error output, will cause the pipeline to terminate.

Run the pipeline by executing the command below from the application directory:

```shell
dagger run node ci/index.mjs
```

:::tip
The `from()`, `withDirectory()`, `withWorkdir()` and `withExec()` methods all return a `Container`, making it easy to chain method calls together and create a pipeline that is intuitive to understand.
:::

</TabItem>
<TabItem value="Python">

<Embed id="yZj9P2N03-D" />

This code listing does the following:

- It creates a Dagger client with `with dagger.Connection()` as before.
- It uses the client's `container().from_()` method to initialize a new container from a base image - again, the `node:16-slim` image. This base image is the Node.js version to use for testing. The `from_()` method returns a new `Container` object with the result.
- It uses the `Container.with_directory()` method to mount the source code directory on the host at the `/src` mount point in the container, and the `Container.with_workdir()` method to set the working directory to that mount point.
  - Notice that the `Container.with_directory()` method accepts additional options to exclude (or include) specific files from the mount. In this case, it excludes the `node_modules` (locally-installed dependencies), `ci` (pipeline code) and `build` (build artifacts) directories.
- It uses the `Container.with_exec()` method to define the commands to install dependencies and run tests in the container - in this case, the commands `npm install` and `npm test -- --watchAll=false`.
- It uses the `Container.stderr()` method to return the error stream of the last executed command. No error output implies successful execution (all tests pass).
  - Failure, indicated by error output, will cause the pipeline to terminate.

Run the pipeline by executing the command below from the application directory:

```shell
dagger run python ci/main.py
```

:::tip
The `from_()`, `with_directory()`, `with_workdir()` and `with_exec()` methods all return a `Container`, making it easy to chain method calls together and create a pipeline that is intuitive to understand.
:::

</TabItem>
</Tabs>

</QuickstartDoc>
