forked from eriwen/gradle-js-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completing RequireJS Task Implementation, Adding Tests
- Loading branch information
Joe Fitzgerald
committed
Feb 8, 2013
1 parent
0a80433
commit 436717d
Showing
14 changed files
with
10,958 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/test/groovy/com/eriwen/gradle/js/RequireJsTaskTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.eriwen.gradle.js | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.process.internal.ExecException | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.Rule | ||
import org.junit.rules.TemporaryFolder | ||
import spock.lang.Specification | ||
|
||
class RequireJsTaskTest extends Specification { | ||
@Rule TemporaryFolder dir = new TemporaryFolder() | ||
|
||
Project project = ProjectBuilder.builder().build() | ||
def task | ||
def src | ||
|
||
def setup() { | ||
project.apply(plugin: JsPlugin) | ||
task = project.tasks.requirejs | ||
src = dir.newFolder() | ||
task.source = src | ||
task.dest = dir.newFile() | ||
} | ||
|
||
def "runWithDefaults"() { | ||
given: | ||
project.requirejs.options = [baseUrl: ".", "paths.jquery": "jam/jquery/dist/jquery", name: "main", out: "main-built.js"] | ||
task.ignoreExitCode = false | ||
addMainFile() | ||
addJamDir() | ||
|
||
when: | ||
task.run() | ||
|
||
then: | ||
notThrown ExecException | ||
} | ||
|
||
def "runWithInvalidMainJs"() { | ||
given: | ||
project.requirejs.options = [baseUrl: ".", "paths.jquery": "jam/jquery/dist/jquery", name: "main", out: "main-built.js"] | ||
task.ignoreExitCode = false | ||
addInvalidMainFile() | ||
addJamDir() | ||
|
||
when: | ||
task.run() | ||
|
||
then: | ||
ExecException e = thrown() | ||
} | ||
|
||
def "runWithBuildProfile"() { | ||
given: | ||
project.requirejs.buildprofile = new File("build.js") | ||
addBuildFile() | ||
addMainFile() | ||
addJamDir() | ||
|
||
when: | ||
task.run() | ||
|
||
then: | ||
notThrown ExecException | ||
} | ||
|
||
def addBuildFile() { | ||
addFile("build.js", new File("src/test/resources/requirejs/build.js").text) | ||
} | ||
|
||
def addMainFile() { | ||
addFile("main.js", new File("src/test/resources/requirejs/main.js").text) | ||
} | ||
|
||
def addInvalidMainFile() { | ||
// call to invalidrequire[] | ||
addFile("main.js", new File("src/test/resources/requirejs/invalidmain.js").text) | ||
} | ||
|
||
def addJamDir() { | ||
new AntBuilder().copy(todir: new File("${project.projectDir.absolutePath}${File.separator}jam").canonicalPath) { | ||
fileset(dir : new File("src/test/resources/requirejs/jam").canonicalPath) | ||
} | ||
} | ||
|
||
def addFile(name,contents) { | ||
def file = new File(project.projectDir as String, name) | ||
file << contents | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
({ | ||
baseUrl: ".", | ||
packages: [ | ||
{ | ||
"name": "jquery", | ||
"location": "jam/jquery", | ||
"main": "dist/jquery.js" | ||
} | ||
], | ||
name: "main", | ||
out: "main-built.js" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
;;&^%#&@%$#@badrequire(["jquery"], function(util) { | ||
//This function is called when scripts/helper/util.js is loaded. | ||
//If util.js calls define(), then this function is not fired until | ||
//util's dependencies have loaded, and the util argument will hold | ||
//the module value for "helper/util". | ||
}); |
Oops, something went wrong.