From 70976476522f9a462c49b9ad8cf9a04b3814eb38 Mon Sep 17 00:00:00 2001 From: cpcwood Date: Wed, 18 Nov 2020 17:24:44 +0000 Subject: [PATCH] add base specs for new useBabel feature --- test.js | 26 ++++++++++++++++++++++++-- tests/es6.js.erb | 6 ++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/es6.js.erb diff --git a/test.js b/test.js index 7ddc0a5..b4d5f42 100755 --- a/test.js +++ b/test.js @@ -56,6 +56,20 @@ test('user config - timeout', () => { }).toThrow("Compilation of './tests/configSleep500.js.erb' timed out after 450ms!") }) +test('user config - useBabel', () => { + const testConfig = { useBabel: true } + expect(transformErb('./tests/es6.js.erb')).toEqual(` + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.ACCOUNT_PATH = void 0; + const ACCOUNT_PATH = '/account'; + exports.ACCOUNT_PATH = ACCOUNT_PATH; + `, testConfig) +}) + // Warnings test('user config - warning - invalid configuration key entered', () => { const testConfig = { 'not-a-key': 'value' } @@ -74,23 +88,31 @@ test('user config - warning - invalid rails option entered', () => { test('user config - warning - invalid engine type entered', () => { const testConfig = { engine: 'not-an-engine' } const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() - transformErb('./tests/erbEngine.js.erb', testConfig) + transformErb('./tests/helloWorld.js.erb', testConfig) expect(consoleSpy).toHaveBeenLastCalledWith('WARNING - User Configuration: "engine": "not-an-engine" is not a valid "engine" value, using default value instead!') }) test('user config - warning - invalid timeout type entered', () => { const testConfig = { timeout: 'not-an-number' } const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() - transformErb('./tests/erbEngine.js.erb', testConfig) + transformErb('./tests/helloWorld.js.erb', testConfig) expect(consoleSpy).toHaveBeenLastCalledWith('WARNING - User Configuration: "timeout": "not-an-number" is not a valid "timeout" value, using default value instead!') }) +test('user config - warning - invalid useBabel type entered', () => { + const testConfig = { useBabel: 'not-a-boolean' } + const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() + transformErb('./tests/helloWorld.js.erb', testConfig) + expect(consoleSpy).toHaveBeenLastCalledWith('WARNING - User Configuration: "useBabel": "not-a-boolean" is not a valid "useBabel" value, using default value instead!') +}) + test('user config - warning - could not be loaded', () => { const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() transformErb('./tests/configNotLoaded.na.erb') expect(consoleSpy).toHaveBeenLastCalledWith('WARNING - User Configuration could not be loaded, please check configuration is correct and report to the maintainers!') }) + // Errors test('error - general failure of childProcess.spawnSync', () => { jest.spyOn(childProcess, 'spawnSync').mockImplementation(() => { return { status: 1, signal: 'test', error: 'test' } }) diff --git a/tests/es6.js.erb b/tests/es6.js.erb new file mode 100644 index 0000000..fd99344 --- /dev/null +++ b/tests/es6.js.erb @@ -0,0 +1,6 @@ +<% + def account_path + return '/account' + end +%> +export const ACCOUNT_PATH = '<%= account_path %>'; \ No newline at end of file