Skip to content

Commit

Permalink
Merge branch 'develop' into release/0.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Steunou committed Aug 28, 2018
2 parents fbfe331 + 201ef9f commit cb4b53e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
22 changes: 16 additions & 6 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ function extract(opts) {
"No extractor found for file '%s'", filename));
}

return results.concat(extractor(_.extend({}, opts, {
filename: filename,
source: fs
.readFileSync(path.resolve(filename))
.toString()
})));
var result = [];
try {
result = extractor(
_.extend({}, opts, {
filename: filename,
source: fs.readFileSync(path.resolve(filename)).toString(),
})
);
} catch (err) {
console.error('Cannot extract for', filename);
if (!opts.catchExtractError) {
throw err;
}
}

return results.concat(result);
}, []);

var pots = pot({
Expand Down
10 changes: 10 additions & 0 deletions test/extract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,14 @@ describe("jspot.extract", function() {
},
/No extractor found for file 'a.custom'/);
});

it("should not throw an error for unsupported formats if catchExtractError is set", function() {
jspot.extract({
catchExtractError: true,
target: tmpdir,
source: ['./test/fixtures/extract/wrong/input/a.js']
});

helpers.assert_file_not_exists(path.join(tmpdir, 'messages.pot'));
});
});
11 changes: 11 additions & 0 deletions test/fixtures/extract/wrong/input/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {withRoute} from 'some/injector'

@withRoute
export class A extends React.Component {

render() {
return (
<h1>Hello World!</h1>
)
}
}
3 changes: 3 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ helpers.assert_files_equal = function(actual_path, expected_path) {
assert.equal(actual.toString(), expected.toString());
};

helpers.assert_file_not_exists = function(actual_path) {
assert.equal(fs.existsSync(actual_path), false);
};

helpers.tmpdir = function(done) {
tmp.dir({
Expand Down
2 changes: 1 addition & 1 deletion utils/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash -e
./node_modules/.bin/jshint `find lib/ test/ -name "*.js"`
./node_modules/.bin/jshint `find lib/ test/ -not -path "test/fixtures/extract/wrong/*" -name "*.js"`
./node_modules/.bin/mocha `find "$@" -name "*.test.js"`

0 comments on commit cb4b53e

Please sign in to comment.