Skip to content

Commit 08d8d71

Browse files
author
Brad Berger
committed
Added empty test suites
1 parent 6895936 commit 08d8d71

21 files changed

+250
-59
lines changed

.codeclimate.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
languages:
2+
JavaScript: true
3+
4+
exclude_paths:
5+
- "test/*"
6+
- "gulpfile.js"
7+
- "protractor.conf.js"
8+
- "karma.conf.js"
9+
- "dist/*"
10+
- "website/*"
11+
12+
engines:
13+
eslint:
14+
enabled: true
15+
16+
ratings:
17+
paths:
18+
- src/**

.eslintignore

Whitespace-only changes.

.eslintrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
rules:
2+
indent:
3+
- 2
4+
quotes:
5+
- 2
6+
- double
7+
linebreak-style:
8+
- 2
9+
- unix
10+
semi:
11+
- 2
12+
- always
13+
globals:
14+
env:
15+
browser: true
16+
extends: 'eslint:recommended'

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
.idea/
21
node_modules/
2+
bower_components/

.jshintrc

-22
This file was deleted.

bower.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "staticjs",
3+
"version": "0.1.0",
4+
"homepage": "https://github.com/bradberger/staticjs",
5+
"authors": [
6+
"Brad Berger <[email protected]>"
7+
],
8+
"description": "A promise based script/css/image resource loader.",
9+
"main": "dist/static.js",
10+
"license": "MPL-2.0",
11+
"ignore": [
12+
"**/.*",
13+
"node_modules",
14+
"bower_components",
15+
"test",
16+
"tests"
17+
]
18+
}

dist/static.compat.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/static.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<head>
3-
<script src="../dist/static.js"></script>
3+
<script src="/js/static.js"></script>
44
</head>
55
<body>
66
<div class="container">

gulpfile.js

+37-18
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,61 @@
1+
/*eslint-env node */
2+
13
var gulp = require("gulp");
24
var uglify = require("gulp-uglify");
35
var concat = require("gulp-concat");
46
var size = require("gulp-size");
5-
var jshint = require("gulp-jshint");
7+
var eslint = require("gulp-eslint");
8+
var connect = require("gulp-connect");
69

710
gulp.task("build", function() {
8-
return gulp.src(__dirname + "/src/static.js")
11+
return gulp
12+
.src(__dirname + "/src/static.js")
913
.pipe(uglify())
1014
.pipe(size({ gzip: true, prettySize: true, showFiles: true }))
11-
.pipe(gulp.dest("dist"));
15+
.pipe(gulp.dest("dist"))
16+
.pipe(connect.reload());
1217
});
1318

1419
gulp.task("build:polyfill", function() {
15-
return gulp.src([
16-
__dirname + "/node_modules/es6-promise/dist/es6-promise.min.js",
17-
__dirname + "/src/polyfills.js",
18-
__dirname + "/src/static.js"
19-
])
20-
.pipe(concat("static.compat.js"))
21-
.pipe(uglify())
22-
.pipe(size({ gzip: true, prettySize: true, showFiles: true }))
23-
.pipe(gulp.dest("dist"));
20+
return gulp
21+
.src([
22+
__dirname + "/node_modules/es6-promise/dist/es6-promise.min.js",
23+
__dirname + "/src/polyfills.js",
24+
__dirname + "/src/static.js"
25+
])
26+
.pipe(concat("static.compat.js"))
27+
.pipe(uglify())
28+
.pipe(size({ gzip: true, prettySize: true, showFiles: true }))
29+
.pipe(gulp.dest("dist"));
2430
});
2531

2632
gulp.task("lint", function() {
27-
return gulp.src(__dirname + "/src/**/*.js")
28-
.pipe(jshint())
29-
.pipe(jshint.reporter("default"));
33+
return gulp
34+
.src(__dirname + "/src/**/*.js")
35+
.pipe(eslint())
36+
.pipe(eslint.format());
3037
});
3138

3239
gulp.task("lint:fail", function() {
33-
return gulp.src(__dirname + "/src/**/*.js")
34-
.pipe(jshint())
35-
.pipe(jshint.reporter("fail"));
40+
return gulp
41+
.src(__dirname + "/src/**/*.js")
42+
.pipe(eslint())
43+
.pipe(eslint.format())
44+
.pipe(eslint.failOnError());
3645
});
3746

3847
gulp.task("watch", function() {
3948
gulp.watch(__dirname + "/src/**/*.js", ["build:all"]);
4049
});
4150

51+
gulp.task("connect", function() {
52+
connect.server({
53+
root: "website",
54+
livereload: true,
55+
port: 3000
56+
});
57+
});
58+
4259
gulp.task("build:all", ["build", "build:polyfill"]);
60+
61+
gulp.task("default", ["connect", "watch"]);

karma.conf.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint-env node */
2+
module.exports = function(config) {
3+
config.set({
4+
5+
// base path that will be used to resolve all patterns (eg. files, exclude)
6+
basePath: "",
7+
8+
// frameworks to use
9+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
10+
frameworks: ["jasmine"],
11+
12+
// list of files / patterns to load in the browser
13+
files: [
14+
"test/**/*.spec.js"
15+
],
16+
17+
// list of files to exclude
18+
exclude: [
19+
],
20+
21+
// preprocess matching files before serving them to the browser
22+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
23+
preprocessors: {
24+
},
25+
26+
// test results reporter to use
27+
// possible values: "dots", "progress"
28+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
29+
reporters: ["progress"],
30+
31+
// web server port
32+
port: 9876,
33+
34+
// enable / disable colors in the output (reporters and logs)
35+
colors: true,
36+
37+
// level of logging
38+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
39+
logLevel: config.LOG_INFO,
40+
41+
// enable / disable watching file and executing tests whenever any file changes
42+
autoWatch: true,
43+
44+
// start these browsers
45+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
46+
browsers: ["Chrome"],
47+
48+
// Continuous Integration mode
49+
// if true, Karma captures browsers, runs the tests and exits
50+
singleRun: false
51+
});
52+
};

package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
{
2-
"name": "elementaryjs/loader",
3-
"version": "0.0.1",
2+
"name": "staticjs",
3+
"version": "0.1.0",
44
"description": "A promise based script/css/image resource loader.",
5-
"main": "dist/loader.js",
5+
"main": "dist/static.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "gulp lint:fail && karma start --single-run"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/elementaryjs/loader.git"
11+
"url": "git+https://github.com/bradberger/staticjs.git"
1212
},
13-
"author": "",
13+
"author": "Brad Berger <[email protected]>",
1414
"license": "MPL-2.0",
1515
"bugs": {
16-
"url": "https://github.com/elementaryjs/loader/issues"
16+
"url": "https://github.com/bradberger/staticjs/issues"
1717
},
18-
"homepage": "https://github.com/elementaryjs/loader#readme",
18+
"homepage": "https://github.com/bradberger/staticjs#readme",
1919
"devDependencies": {
2020
"es6-promise": "^2.3.0",
2121
"gulp": "^3.9.0",
2222
"gulp-concat": "^2.6.0",
23+
"gulp-connect": "^2.2.0",
24+
"gulp-eslint": "^1.0.0",
2325
"gulp-jshint": "^1.11.2",
2426
"gulp-size": "^1.2.3",
2527
"gulp-uglify": "^1.2.0"

src/polyfills.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ if (!String.prototype.endsWith) {
179179
}
180180

181181
if (!window.requestAnimationFrame)
182-
window.requestAnimationFrame = function(callback, element) {
182+
window.requestAnimationFrame = function(callback) {
183183
var currTime = new Date().getTime();
184184
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
185185
var id = window.setTimeout(function() { callback(currTime + timeToCall); },

src/static.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
(function(window) {
22

3-
var BUNDLE_INTERVAL_DURATION = 100;
4-
var emptyFunc = function() { return null; };
3+
var noop = function() { };
54
var storage = window.localStorage || {
6-
getItem: emptyFunc,
7-
setItem: emptyFunc,
8-
removeItem: emptyFunc
5+
getItem: noop,
6+
setItem: noop,
7+
removeItem: noop
98
};
109

1110
var isJavaScript = function(url) {
12-
return url.toString().toLowerCase().endsWith(".js");
11+
return url.toString().toLowerCase().endsWith(".js");
1312
};
1413

1514
var isCss = function(url) {

test/caching.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*eslint-env karma,jasmine */
2+
describe("caching test suite", function() {
3+
xit("should be implemented", function() {
4+
5+
});
6+
});

test/css.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*eslint-env karma,jasmine */
2+
describe("css test suite", function() {
3+
xit("should be implemented", function() {
4+
5+
});
6+
});

test/images.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*eslint-env karma,jasmine */
2+
describe("images test suite", function() {
3+
xit("should be implemented", function() {
4+
5+
});
6+
});

test/js.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*eslint-env karma,jasmine */
2+
describe("javascript test suite", function() {
3+
xit("should be implemented", function() {
4+
5+
});
6+
});

website/index.html

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!doctype html>
2+
<head>
3+
<script src="/js/static.compat.js"></script>
4+
</head>
5+
<body>
6+
<div class="container">
7+
<button class="btn btn-primary btn-block">Not loaded</button>
8+
</div>
9+
<script>
10+
// Promise when a anonymous bundle is loaded.
11+
$static.load("https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css").then(function() {
12+
console.info("Bootstrap CSS loaded!");
13+
});
14+
15+
// Promise when a named bundle is loaded.
16+
$static.ready("jquery").then(function() {
17+
18+
setTimeout(function() {
19+
console.log("jquery ready", "undefined" !== typeof jQuery);
20+
}, 100);
21+
22+
$static.load([
23+
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js",
24+
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css",
25+
"https://cdn.jsdelivr.net/jquery/3.0.0-alpha1/jquery.min.js"
26+
]).then(function() {
27+
jQuery(".btn").html("Bootstrap loaded!");
28+
});
29+
30+
});
31+
32+
// Callback when a named bundle is loaded.
33+
$static.ready("jquery", function() {
34+
console.info("jQuery done again!");
35+
});
36+
37+
// Define a bundle.
38+
setTimeout(function() {
39+
$static.load("https://cdn.jsdelivr.net/jquery/3.0.0-alpha1/jquery.min.js", "jquery");
40+
}, 1000);
41+
42+
// Get the resources and inject the contents
43+
// as innerHTML inside their own element.
44+
$static.get("https://cdn.jsdelivr.net/jquery/3.0.0-alpha1/jquery.min.js")
45+
.then(function() {
46+
console.info("jquery.get.done");
47+
});
48+
49+
// // Cache the resources in localStorage, and inject
50+
// // the content s as innerHTML inside their own element.
51+
$static.cache("https://cdn.jsdelivr.net/jquery/3.0.0-alpha1/jquery.min.js")
52+
.then(function() {
53+
console.info("jquery.cached");
54+
});
55+
56+
// // Load the resources in synchronously.
57+
$static.sync([
58+
"https://cdn.jsdelivr.net/jquery/3.0.0-alpha1/jquery.min.js",
59+
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js",
60+
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css"
61+
]);
62+
</script>
63+
</body>

website/js/static.compat.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../dist/static.compat.js

website/js/static.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../dist/static.js

0 commit comments

Comments
 (0)