使用 frontend-maven-plugin 从 Maven 运行 jest

Don*_*sek 7 maven jestjs

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>
Run Code Online (Sandbox Code Playgroud)

Viz*_*z85 5

我们使用 npm 和 jest 进行测试,这是配置:

<execution>
    <id>run tests</id>
    <goals>
        <goal>npm</goal>
    </goals>
    <configuration>
        <arguments>test</arguments>
    </configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)

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