-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add babel-plugin-formatjs test cases
- Loading branch information
Showing
2 changed files
with
631 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { transformSync } from '@babel/core'; | ||
import getBabePresetConfigForMcAppForProduction from './production'; | ||
|
||
describe('babel-plugin-formatjs', () => { | ||
const code = ` | ||
import { defineMessages } from 'react-intl'; | ||
const messages = defineMessages({ | ||
welcome: { | ||
id: 'app.welcome', | ||
defaultMessage: 'Welcome, {name}!', | ||
description: 'Message to greet the user by name', | ||
}, | ||
}); | ||
`; | ||
|
||
it('should remove description by default', () => { | ||
const config = getBabePresetConfigForMcAppForProduction(null); | ||
|
||
const result = transformSync(code, { | ||
filename: 'dummy-file-name.js', | ||
presets: config.presets, | ||
plugins: config.plugins, | ||
}); | ||
|
||
expect(result.code).toMatchInlineSnapshot(` | ||
""use strict"; | ||
var _reactIntl = require("react-intl"); | ||
const messages = (0, _reactIntl.defineMessages)({ | ||
welcome: { | ||
id: "app.welcome", | ||
defaultMessage: "Welcome, {name}!" | ||
} | ||
});" | ||
`); | ||
}); | ||
|
||
it('should remove defaultMessage when i18nRemoveDefaultMessage is true', () => { | ||
const config = getBabePresetConfigForMcAppForProduction(null, { | ||
i18nRemoveDefaultMessage: true, | ||
}); | ||
|
||
const result = transformSync(code, { | ||
filename: 'dummy-file-name.js', | ||
presets: config.presets, | ||
plugins: config.plugins, | ||
}); | ||
|
||
expect(result.code).toMatchInlineSnapshot(` | ||
""use strict"; | ||
var _reactIntl = require("react-intl"); | ||
const messages = (0, _reactIntl.defineMessages)({ | ||
welcome: { | ||
id: "app.welcome" | ||
} | ||
});" | ||
`); | ||
}); | ||
|
||
it('should parse defaultMessage into AST when i18nAst is true', () => { | ||
const config = getBabePresetConfigForMcAppForProduction(null, { | ||
i18nAst: true, | ||
}); | ||
|
||
const result = transformSync(code, { | ||
filename: 'dummy-file-name.js', | ||
presets: config.presets, | ||
plugins: config.plugins, | ||
}); | ||
|
||
expect(result.code).toMatchInlineSnapshot(` | ||
""use strict"; | ||
var _reactIntl = require("react-intl"); | ||
const messages = (0, _reactIntl.defineMessages)({ | ||
welcome: { | ||
id: "app.welcome", | ||
defaultMessage: [{ | ||
"type": 0, | ||
"value": "Welcome, " | ||
}, { | ||
"type": 1, | ||
"value": "name" | ||
}, { | ||
"type": 0, | ||
"value": "!" | ||
}] | ||
} | ||
});" | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.