Skip to content

Commit

Permalink
Move test assertions to the top level to ensure that they run
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 8, 2019
1 parent b39c93f commit ce91919
Showing 1 changed file with 17 additions and 13 deletions.
Expand Up @@ -8,27 +8,31 @@ const code = multiline([
"}"
]);

let programPath;
let forOfPath;
let functionPath;

transform(code, {
configFile: false,
plugins: [
"../../../../lib",
{
post({ path }) {
programPath = path;
path.traverse({
Program(path) {
expect(Object.keys(path.scope.bindings)).toEqual(["foo", "bar"]);
},
ForOfStatement(path) {
// for declarations should be transformed to for bindings
expect(path.scope.bindings).toEqual({});
// The body should be wrapped into closure
expect(path.get("body").scope.bindings).toEqual({});
},
FunctionExpression(path) {
expect(Object.keys(path.scope.bindings)).toEqual(["foo", "bar", "qux", "quux"]);
}
})
ForOfStatement(path) { forOfPath = path },
FunctionExpression(path) { functionPath = path }
});
}
}
]
});

expect(Object.keys(programPath.scope.bindings)).toEqual(["foo", "bar"]);

// for declarations should be transformed to for bindings
expect(forOfPath.scope.bindings).toEqual({});
// The body should be wrapped into closure
expect(forOfPath.get("body").scope.bindings).toEqual({});

expect(Object.keys(functionPath.scope.bindings)).toEqual(["foo", "bar", "qux", "quux"]);

0 comments on commit ce91919

Please sign in to comment.