@@ -6,6 +6,11 @@ var resolveFrom = require('resolve-from');
6
6
var hasGenerator = require ( 'has-generator' ) ;
7
7
var serializeValue = require ( './serialize-value' ) ;
8
8
var send = require ( './send' ) ;
9
+ var hasha = require ( 'hasha' ) ;
10
+ var hashObj = require ( 'hash-obj' ) ;
11
+ var xdgBasedir = require ( 'xdg-basedir' ) ;
12
+ var path = require ( 'path' ) ;
13
+ var cache = require ( 'cacha' ) ( path . join ( xdgBasedir . cache , 'ava' ) ) ;
9
14
10
15
var testPath = process . argv [ 2 ] ;
11
16
@@ -31,24 +36,6 @@ var options = {
31
36
plugins : [ powerAssert ]
32
37
} ;
33
38
34
- // check if test files required ava and show error, when they didn't
35
- exports . avaRequired = false ;
36
-
37
- process . on ( 'uncaughtException' , function ( exception ) {
38
- send ( 'uncaughtException' , { exception : serializeValue ( exception ) } ) ;
39
- } ) ;
40
-
41
- // include test file
42
- var transpiled = babel . transformFileSync ( testPath , options ) ;
43
- requireFromString ( transpiled . code , testPath , {
44
- appendPaths : module . paths
45
- } ) ;
46
-
47
- // if ava was not required, show an error
48
- if ( ! exports . avaRequired ) {
49
- throw new Error ( 'No tests found in ' + testPath + ', make sure to import "ava" at the top of your test file' ) ;
50
- }
51
-
52
39
// parse and re-emit ava messages
53
40
process . on ( 'message' , function ( message ) {
54
41
if ( ! message . ava ) {
@@ -82,6 +69,35 @@ process.on('ava-teardown', function () {
82
69
setTimeout ( exit , 100 ) ;
83
70
} ) ;
84
71
72
+ process . on ( 'uncaughtException' , function ( exception ) {
73
+ send ( 'uncaughtException' , { exception : serializeValue ( exception ) } ) ;
74
+ } ) ;
75
+
76
+ var hash = hashObj ( {
77
+ code : hasha . fromFileSync ( testPath ) ,
78
+ avaVersion : require ( '../package.json' ) . version
79
+ } ) ;
80
+
81
+ var code = cache . getSync ( hash , 'utf8' ) ;
82
+
83
+ if ( code === undefined ) {
84
+ code = babel . transformFileSync ( testPath , options ) . code ;
85
+ cache . setSync ( hash , code , 'utf8' ) ;
86
+ }
87
+
88
+ // check if test files required ava and show error, when they didn't
89
+ exports . avaRequired = false ;
90
+
91
+ // include test file
92
+ requireFromString ( code , testPath , {
93
+ appendPaths : module . paths
94
+ } ) ;
95
+
96
+ // if ava was not required, show an error
97
+ if ( ! exports . avaRequired ) {
98
+ throw new Error ( 'No tests found in ' + testPath + ', make sure to import "ava" at the top of your test file' ) ;
99
+ }
100
+
85
101
function exit ( ) {
86
102
send ( 'teardown' ) ;
87
103
}
0 commit comments