From 4467f28b8a2c42947acfc6ecff882b79a358f6f8 Mon Sep 17 00:00:00 2001 From: Harrel Date: Sun, 8 Oct 2023 22:27:26 +0200 Subject: [PATCH] add bunTask unit test --- .../gradle/node/bun/task/BunTaskTest.groovy | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/groovy/com/github/gradle/node/bun/task/BunTaskTest.groovy diff --git a/src/test/groovy/com/github/gradle/node/bun/task/BunTaskTest.groovy b/src/test/groovy/com/github/gradle/node/bun/task/BunTaskTest.groovy new file mode 100644 index 00000000..252a727e --- /dev/null +++ b/src/test/groovy/com/github/gradle/node/bun/task/BunTaskTest.groovy @@ -0,0 +1,69 @@ +package com.github.gradle.node.bun.task + +import com.github.gradle.node.pnpm.task.PnpmTask +import com.github.gradle.node.task.AbstractTaskTest +import com.github.gradle.node.util.PlatformHelperKt + +class BunTaskTest extends AbstractTaskTest { + def "exec bun task"() { + given: + nodeExtension.resolvedPlatform.set(PlatformHelperKt.parsePlatform("Linux", "x86_64", {})) + + def task = project.tasks.create('simple', BunTask) + mockProjectApiHelperExec(task) + task.args.set(['a', 'b']) + task.environment.set(['a': '1']) + task.ignoreExitValue.set(true) + task.workingDir.set(projectDir) + + when: + project.evaluate() + task.exec() + + then: + task.args.set(['a', 'b']) + 1 * execSpec.setIgnoreExitValue(true) + 1 * execSpec.setEnvironment({ it['a'] == '1' && containsPath(it) }) + 1 * execSpec.setExecutable('bun') + 1 * execSpec.setArgs(['a', 'b']) + } + + def "exec bun task (windows)"() { + given: + nodeExtension.resolvedPlatform.set(PlatformHelperKt.parsePlatform("Windows", "x86_64", {})) + + def task = project.tasks.create('simple', BunTask) + mockProjectApiHelperExec(task) + task.args.set(['a', 'b']) + task.environment.set(['a': '1']) + task.ignoreExitValue.set(true) + task.workingDir.set(projectDir) + + when: + project.evaluate() + task.exec() + + then: + task.args.get() == ['a', 'b'] + 1 * execSpec.setIgnoreExitValue(true) + 1 * execSpec.setEnvironment({ it['a'] == '1' && containsPath(it) }) + 1 * execSpec.setExecutable('bun.cmd') + 1 * execSpec.setArgs(['a', 'b']) + } + + def "exec bun task (download)"() { + given: + nodeExtension.resolvedPlatform.set(PlatformHelperKt.parsePlatform("Linux", "x86_64", {})) + nodeExtension.download.set(true) + + def task = project.tasks.create('simple', PnpmTask) + mockProjectApiHelperExec(task) + + when: + project.evaluate() + task.exec() + + then: + 1 * execSpec.setIgnoreExitValue(false) + } +}