Skip to content

Commit 196cd89

Browse files
committed
Add grunt testem alias + some DRY in Gruntfile.js
refs #2990 - add an alias for grunt testem - add test-setup task to dry up some tasks
1 parent 3c86f67 commit 196cd89

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

Gruntfile.js

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ var _ = require('lodash'),
810810
grunt.log.write('no test provided');
811811
}
812812

813-
grunt.task.run('setTestEnv', 'shell:test:' + test);
813+
grunt.task.run('test-setup', 'shell:test:' + test);
814814
});
815815

816816
// ### Validate
@@ -825,21 +825,30 @@ var _ = require('lodash'),
825825
grunt.registerTask('validate', 'Run tests and lint code',
826826
['init', 'test-all']);
827827

828-
// ### Test
828+
// ### Test-All
829829
// **Main testing task**
830830
//
831-
// `grunt test` will lint and test your pre-built local Ghost codebase.
831+
// `grunt test-all` will lint and test your pre-built local Ghost codebase.
832832
//
833-
// `grunt test` runs jshint and jscs as well as the 4 test suites. See the individual sub tasks below for
833+
// `grunt test-all` runs jshint and jscs as well as all 6 test suites. See the individual sub tasks below for
834834
// details of each of the test suites.
835835
//
836836
grunt.registerTask('test-all', 'Run tests and lint code',
837-
['jshint', 'jscs', 'test-routes', 'test-module', 'test-unit', 'test-integration', 'test-functional', 'shell:testem']);
837+
['lint', 'test-routes', 'test-module', 'test-unit', 'test-integration', 'test-functional', 'shell:testem']
838+
);
838839

839840
// ### Lint
840841
//
841842
// `grunt lint` will run the linter and the code style checker so you can make sure your code is pretty
842-
grunt.registerTask('lint', 'Run the code style checks and linter', ['jshint', 'jscs']);
843+
grunt.registerTask('lint', 'Run the code style checks and linter',
844+
['jshint', 'jscs']
845+
);
846+
847+
// ### test-setup *(utility)(
848+
// `grunt test-setup` will run all the setup tasks required for running tests
849+
grunt.registerTask('test-setup', 'Setup ready to run tests',
850+
['clean:test', 'setTestEnv', 'ensureConfig']
851+
);
843852

844853
// ### Unit Tests *(sub task)*
845854
// `grunt test-unit` will run just the unit tests
@@ -859,7 +868,8 @@ var _ = require('lodash'),
859868
// Unit tests do **not** touch the database.
860869
// A coverage report can be generated for these tests using the `grunt test-coverage` task.
861870
grunt.registerTask('test-unit', 'Run unit tests (mocha)',
862-
['clean:test', 'setTestEnv', 'ensureConfig', 'mochacli:unit']);
871+
['test-setup', 'mochacli:unit']
872+
);
863873

864874
// ### Integration tests *(sub task)*
865875
// `grunt test-integration` will run just the integration tests
@@ -888,7 +898,8 @@ var _ = require('lodash'),
888898
//
889899
// A coverage report can be generated for these tests using the `grunt test-coverage` task.
890900
grunt.registerTask('test-integration', 'Run integration tests (mocha + db access)',
891-
['clean:test', 'setTestEnv', 'ensureConfig', 'mochacli:integration']);
901+
['test-setup', 'mochacli:integration']
902+
);
892903

893904
// ### Route tests *(sub task)*
894905
// `grunt test-routes` will run just the route tests
@@ -909,24 +920,22 @@ var _ = require('lodash'),
909920
// are working as expected, including checking the headers and status codes received. It is very easy and
910921
// quick to test many permutations of routes / urls in the system.
911922
grunt.registerTask('test-routes', 'Run functional route tests (mocha)',
912-
['clean:test', 'setTestEnv', 'ensureConfig', 'mochacli:routes']);
923+
['test-setup', 'mochacli:routes']
924+
);
913925

914926
// ### Module tests *(sub task)*
915927
// `grunt test-module` will run just the module tests
916928
//
917929
// The purpose of the module tests is to ensure that Ghost can be used as an npm module and exposes all
918930
// required methods to interact with it.
919931
grunt.registerTask('test-module', 'Run functional module tests (mocha)',
920-
['clean:test', 'setTestEnv', 'ensureConfig', 'mochacli:module']);
932+
['test-setup', 'mochacli:module']
933+
);
921934

922-
// ### Functional tests for the setup process
923-
// `grunt test-functional-setup will run just the functional tests for the setup page.
924-
//
925-
// Setup only works with a brand new database, so it needs to run isolated from the rest of
926-
// the functional tests.
927-
grunt.registerTask('test-functional-setup', 'Run functional tests for setup',
928-
['clean:test', 'setTestEnv', 'ensureConfig', 'cleanDatabase', 'express:test',
929-
'spawnCasperJS:setup', 'express:test:stop']
935+
// ### Ember unit tests *(sub task)*
936+
// `grunt testem` will run just the ember unit tests
937+
grunt.registerTask('testem', 'Run the ember unit tests',
938+
['test-setup', 'shell:testem']
930939
);
931940

932941
// ### Functional tests *(sub task)*
@@ -948,8 +957,16 @@ var _ = require('lodash'),
948957
// The purpose of the functional tests is to ensure that Ghost is working as is expected from a user perspective
949958
// including buttons and other important interactions in the admin UI.
950959
grunt.registerTask('test-functional', 'Run functional interface tests (CasperJS)',
951-
['clean:test', 'setTestEnv', 'ensureConfig', 'cleanDatabase', 'express:test', 'spawnCasperJS', 'express:test:stop',
952-
'test-functional-setup']
960+
['test-setup', 'cleanDatabase', 'express:test', 'spawnCasperJS', 'express:test:stop', 'test-functional-setup']
961+
);
962+
963+
// ### Functional tests for the setup process
964+
// `grunt test-functional-setup will run just the functional tests for the setup page.
965+
//
966+
// Setup only works with a brand new database, so it needs to run isolated from the rest of
967+
// the functional tests.
968+
grunt.registerTask('test-functional-setup', 'Run functional tests for setup',
969+
['test-setup', 'cleanDatabase', 'express:test', 'spawnCasperJS:setup', 'express:test:stop']
953970
);
954971

955972
// ### Coverage
@@ -962,7 +979,8 @@ var _ = require('lodash'),
962979
//
963980
// Key areas for coverage are: helpers and theme elements, apps / GDK, the api and model layers.
964981
grunt.registerTask('test-coverage', 'Generate unit and integration (mocha) tests coverage report',
965-
['clean:test', 'setTestEnv', 'ensureConfig', 'shell:coverage']);
982+
['test-setup', 'shell:coverage']
983+
);
966984

967985
// ## Building assets
968986
//

0 commit comments

Comments
 (0)