Skip to content

Commit

Permalink
feat(config): Add initial e2e custom context feature test
Browse files Browse the repository at this point in the history
  • Loading branch information
ernsheong committed Feb 16, 2016
1 parent 0277eac commit 3c88ef3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,16 @@ var normalizeConfig = function (config, configFilePath) {
// resolve basePath
config.basePath = path.resolve(path.dirname(configFilePath), config.basePath)

// resolve customContextFile and customDebugFile
config.customContextFile = config.customContextFile &&
path.resolve(path.dirname(configFilePath), config.customContextFile)
config.customDebugFile = config.customDebugFile &&
path.resolve(path.dirname(configFilePath), config.customDebugFile)

// always ignore the config file itself
config.exclude.push(configFilePath)
} else {
config.basePath = path.resolve(config.basePath || '.')

config.customContextFile = config.customContextFile && path.resolve(config.basePath, config.customContextFile)
config.customDebugFile = config.customDebugFile && path.resolve(config.basePath, config.customDebugFile)
}

config.files = config.files.map(createPatternObject).map(createPatternMapper(basePathResolve))
config.exclude = config.exclude.map(basePathResolve)
config.customContextFile = config.customContextFile && basePathResolve(config.customContextFile)
config.customDebugFile = config.customDebugFile && basePathResolve(config.customDebugFile)

// normalize paths on windows
config.basePath = helper.normalizeWinPath(config.basePath)
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/custom-context.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@current
Feature: Custom Context File
In order to use Karma
As a person who wants to write great tests
I want Karma to use a custom context file

Scenario: Custom context.html file
Given a configuration with:
"""
files = ['context/*.js'];
browsers = ['PhantomJS'];
plugins = [
'karma-jasmine',
'karma-phantomjs-launcher'
];
singleRun = false;
customContextFile = 'context/context2.html'
"""
When I start Karma
Then it passes with:
"""
.
PhantomJS
"""
37 changes: 37 additions & 0 deletions test/e2e/support/context/context2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<!--
This is the execution context.
Loaded within the iframe.
Reloaded before every execution run.
-->
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
</head>
<body>
<!-- The scripts need to be in the body DOM element, as some test running frameworks need the body
to have already been created so they can insert their magic into it. For example, if loaded
before body, Angular Scenario test framework fails to find the body and crashes and burns in
an epic manner. -->
<script type="text/javascript">
// sets window.__karma__ and overrides console and error handling
// Use window.opener if this was opened by someone else - in a new window
if (window.opener) {
window.opener.karma.setupContext(window);
} else {
window.parent.karma.setupContext(window);
}

// All served files with the latest timestamps
%MAPPINGS%
</script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script type="text/javascript">
window.__karma__.loaded();
window.__karma__.customContext = true;
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions test/e2e/support/context/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('custom context file', function () {
it('should pass', function () {
expect(window.__karma__.customContext).toBe(true)
})
})

0 comments on commit 3c88ef3

Please sign in to comment.