Skip to content

Commit

Permalink
Merge pull request #31 from cpcwood/update-for-jest-v28+
Browse files Browse the repository at this point in the history
Update for jest v28+
  • Loading branch information
cpcwood committed Sep 12, 2022
2 parents e161c1d + 673ac8d commit 1bb230f
Show file tree
Hide file tree
Showing 7 changed files with 1,779 additions and 1,951 deletions.
36 changes: 35 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# Contributing

Feel free to ask questions using [issues](https://github.com/cpcwood/jest-erb-transformer/issues) or fork and [create a pull request](https://github.com/cpcwood/jest-erb-transformer/compare) if you have any improvements.
Feel free to ask questions using [issues](https://github.com/cpcwood/jest-erb-transformer/issues) or fork and [create a pull request](https://github.com/cpcwood/jest-erb-transformer/compare) if you have any improvements.

## Setup

The project uses the [`yarn`](https://yarnpkg.com/) package manager, please install by following Yarn's [documentation](https://yarnpkg.com/getting-started/install).

To setup the project: clone the repository, navigate to the project's root directory, and install the dependencies using:

```sh
yarn install
```

## Tests

The transformer is tested using Jest.

Run the unit tests using:

```sh
yarn test
```

Run the end to end tests using:

```sh
yarn e2e
```

## Code Quality

[`eslint`](https://eslint.org/) is used for code linting. Run using the lint command:

```sh
yarn lint
```
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Chris Wood
Copyright (c) 2022 Chris Wood

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ Custom transformer for compiling Embedded Ruby template files (```.erb```) for u

## Install

Add to project using npm:

```sh
npm install jest-erb-transformer --save-dev
```

Add to project using Yarn:
Add to project using your package manager, e.g. yarn:

```sh
yarn add jest-erb-transformer --dev
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ function processFile (fileContent, filePath, config) {
module.exports = {
process (fileContent, filePath, jestConfig) {
const config = loadConfig(filePath, jestConfig)
return processFile(fileContent, filePath, config)
return {
code: processFile(fileContent, filePath, config)
}
}
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
},
"homepage": "https://github.com/cpcwood/jest-erb-transformer#readme",
"dependencies": {
"@babel/core": "^7.15.5",
"babel-jest": "^27.2.1"
"@babel/core": "^7.19.0",
"babel-jest": "^29.0.3"
},
"devDependencies": {
"@babel/preset-env": "^7.15.6",
"coveralls": "^3.1.0",
"eslint": "^7.2.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.21.1",
"@babel/preset-env": "^7.19.0",
"coveralls": "^3.1.1",
"eslint": "^8.23.1",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^27.2.1",
"eslint-plugin-promise": "^6.0.1",
"jest": "^29.0.3",
"jest-erb-transformer": "./"
}
}
24 changes: 12 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ afterEach(() => {
// Features
// ========================
test('compiles a simple file', () => {
expect(transformErb('./tests/helloWorld.js.erb')).toEqual("var helloWorld = 'Hello World'")
expect(transformErb('./tests/helloWorld.js.erb').code).toEqual("var helloWorld = 'Hello World'")
})

test('empty file', () => {
expect(transformErb('./tests/emptyFile.js.erb')).toEqual('')
expect(transformErb('./tests/emptyFile.js.erb').code).toEqual('')
})

test('compiles a file with the ruby erb engine', () => {
expect(transformErb('./tests/erbEngine.js.erb').trim()).toEqual("var engine = 'erb'")
expect(transformErb('./tests/erbEngine.js.erb').code.trim()).toEqual("var engine = 'erb'")
})

test('user config - rails application', () => {
const testConfig = { application: 'rails' }
expect(transformErb('./tests/configApplication.js.erb', testConfig)).toEqual("var application = 'rails'")
expect(transformErb('./tests/configApplication.js.erb', testConfig).code).toEqual("var application = 'rails'")
})

test('user config - ruby application', () => {
const testConfig = { application: 'ruby' }
expect(transformErb('./tests/configApplication.js.erb', testConfig)).toEqual("var application = 'ruby'")
expect(transformErb('./tests/configApplication.js.erb', testConfig).code).toEqual("var application = 'ruby'")
})

test('user config - erubi compiler', () => {
const testConfig = { engine: 'erubi' }
expect(transformErb('./tests/erbEngine.js.erb', testConfig).trim()).toEqual("var engine = 'erubi'")
expect(transformErb('./tests/erbEngine.js.erb', testConfig).code.trim()).toEqual("var engine = 'erubi'")
})

test('user config - erb compiler', () => {
const testConfig = { engine: 'erb' }
expect(transformErb('./tests/erbEngine.js.erb', testConfig).trim()).toEqual("var engine = 'erb'")
expect(transformErb('./tests/erbEngine.js.erb', testConfig).code.trim()).toEqual("var engine = 'erb'")
})

test('user config - timeout', () => {
Expand All @@ -52,21 +52,21 @@ test('user config - timeout', () => {

test('user config - babelConfig false', () => {
const testConfig = { babelConfig: false }
const result = transformErb('./tests/es6.js.erb', testConfig)
const result = transformErb('./tests/es6.js.erb', testConfig).code
expect(result).toContain('// a comment')
expect(result).toContain("export const ACCOUNT_PATH = '/account';")
})

test('user config - babelConfig true', () => {
const testConfig = { babelConfig: true }
const result = transformErb('./tests/es6.js.erb', testConfig)
const result = transformErb('./tests/es6.js.erb', testConfig).code
expect(result).toContain('exports.ACCOUNT_PATH = ACCOUNT_PATH;')
expect(result).toContain('a comment')
})

test('user config - babelConfig path', () => {
const testConfig = { babelConfig: './tests/testBabelConfig.js' }
const result = transformErb('./tests/es6.js.erb', testConfig)
const result = transformErb('./tests/es6.js.erb', testConfig).code
expect(result).toContain('exports.ACCOUNT_PATH = ACCOUNT_PATH;')
expect(result).not.toContain('a comment')
})
Expand All @@ -78,7 +78,7 @@ test('user config - babelConfig inline', () => {
minified: true
}
}
const result = transformErb('./tests/es6.js.erb', testConfig)
const result = transformErb('./tests/es6.js.erb', testConfig).code
expect(result).toContain('exports.ACCOUNT_PATH=ACCOUNT_PATH;')
expect(result).not.toContain('a comment')
})
Expand Down Expand Up @@ -137,7 +137,7 @@ test('error - general failure of childProcess.spawnSync', () => {
// Legacy versions
// ========================
test('(Jest v26) compiles a simple file', () => {
expect(transformErbV26('./tests/helloWorld.js.erb')).toEqual("var helloWorld = 'Hello World'")
expect(transformErbV26('./tests/helloWorld.js.erb').code).toEqual("var helloWorld = 'Hello World'")
})

// Spec Helpers
Expand Down
Loading

0 comments on commit 1bb230f

Please sign in to comment.