首页 > 解决方案 > 使用 frontend-maven-plugin 从 maven 运行 jest

问题描述

jest 的文档似乎都假设我们熟悉整个 yarn/npm/node 生态系统(我是一个 java 人,所以不是那么多)。

我在pom.xml运行 webpack 中有以下内容。我只是不知道如何扩展它,以便 mvn test 开玩笑地运行单元测试

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.6</version>
    <configuration>
        <installDirectory>target</installDirectory>
    </configuration>
    <executions>
        <execution>
            <id>install node and npm</id>
            <goals>
                <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
                <nodeVersion>v10.11.0</nodeVersion>
                <npmVersion>6.4.1</npmVersion>
            </configuration>
        </execution>
        <execution>
            <id>npm install</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
                <arguments>install</arguments>
            </configuration>
        </execution>
        <execution>
            <id>webpack build</id>
            <goals>
                <goal>webpack</goal>
            </goals>
        </execution>
        <execution>
            <id>test</id>
            <goals>
                <goal>yarn</goal>
            </goals>
            <phase>test</phase>
            <configuration>
                <arguments>test</arguments>
                <environmentVariables>
                    <CI>true</CI>
                </environmentVariables>
            </configuration>
        </execution>
    </executions>
</plugin>

标签: mavenjestjs

解决方案


我们正在使用带有 jest 的 npm 进行测试,这是配置:

<execution>
    <id>run tests</id>
    <goals>
        <goal>npm</goal>
    </goals>
    <configuration>
        <arguments>test</arguments>
    </configuration>
</execution>

如果测试不满足,构建将失败


推荐阅读