Skip to content

Commit

Permalink
Integration tests for chunks configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pirelenito committed Jan 2, 2018
1 parent 52c110f commit 5884302
Show file tree
Hide file tree
Showing 41 changed files with 335 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.3",
"lodash.merge": "^4.6.0",
"lodash.uniq": "^4.5.0",
"node-sass": "^4.5.2",
"null-loader": "^0.1.1",
Expand Down
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions spec/fixtures/project-with-independent-page/sagui.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
pages: ['index', 'about', { name: 'demo', independent: true }],
chunks: {
vendor: true,
common: true,
}
}
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-independent-page/src/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
5 changes: 5 additions & 0 deletions spec/fixtures/project-with-independent-page/src/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import shared from './shared'
import dependencyA from 'dependencyA'

shared()
dependencyA()
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-independent-page/src/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
7 changes: 7 additions & 0 deletions spec/fixtures/project-with-independent-page/src/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import shared from './shared'
import dependencyA from 'dependencyA'
import dependencyB from 'dependencyB'

shared()
dependencyA()
dependencyB()
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-independent-page/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
5 changes: 5 additions & 0 deletions spec/fixtures/project-with-independent-page/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import shared from './shared'
import dependencyB from 'dependencyB'

shared()
dependencyB()
1 change: 1 addition & 0 deletions spec/fixtures/project-with-independent-page/src/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => console.log('shared module')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
pages: ['index', 'about'],
chunks: {
common: false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import shared from './shared'

shared()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import shared from './shared'

shared()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => console.log('shared module')
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
pages: ['index', 'about'],
chunks: {
vendor: true
}
}
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-two-pages-enabled-vendor/src/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import shared from './shared'
import dependencyA from 'dependencyA'

shared()
dependencyA()
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-two-pages-enabled-vendor/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import shared from './shared'
import dependencyB from 'dependencyB'

shared()
dependencyB()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => console.log('shared module')
3 changes: 3 additions & 0 deletions spec/fixtures/project-with-two-pages/sagui.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
pages: ['index', 'about']
}
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-two-pages/src/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
3 changes: 3 additions & 0 deletions spec/fixtures/project-with-two-pages/src/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import shared from './shared'

shared()
11 changes: 11 additions & 0 deletions spec/fixtures/project-with-two-pages/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div id="root"></div>
</body>
</html>
3 changes: 3 additions & 0 deletions spec/fixtures/project-with-two-pages/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import shared from './shared'

shared()
1 change: 1 addition & 0 deletions spec/fixtures/project-with-two-pages/src/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => console.log('shared module')
100 changes: 100 additions & 0 deletions spec/integration/index.integration-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,106 @@ describe('[integration] sagui', function () {
})
})

describe('chunks', () => {
describe('project with two pages on build', () => {
const projectFixture = path.join(__dirname, '../fixtures/project-with-two-pages')
beforeEach(function () {
fs.copySync(projectFixture, projectPath, { overwrite: true })
return sagui({ projectPath, action: actions.BUILD })
})

it('should have created a common.js file', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
expect(files.filter((file) => file.match(/common.+\.js$/))).not.to.be.empty
})

it('should NOT have created a vendor.js file', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
expect(files.filter((file) => file.match(/vendor.+\.js$/))).to.be.empty
})
})

describe('project with two pages and disabled common chunks on build', () => {
const projectFixture = path.join(__dirname, '../fixtures/project-with-two-pages-disabled-common')
beforeEach(function () {
fs.copySync(projectFixture, projectPath, { overwrite: true })
return sagui({ projectPath, action: actions.BUILD })
})

it('should not have created a common.js file', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
expect(files.filter((file) => file.match(/common.+\.js$/))).to.be.empty
})

it('should NOT have created a vendor.js file', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
expect(files.filter((file) => file.match(/vendor.+\.js$/))).to.be.empty
})
})

describe('project with two pages and enabled vendor chunks on build', () => {
const projectFixture = path.join(__dirname, '../fixtures/project-with-two-pages-enabled-vendor')
beforeEach(function () {
fs.copySync(projectFixture, projectPath, { overwrite: true })
return sagui({ projectPath, action: actions.BUILD })
})

it('should have created a common.js file without the content of the node_modules dependencies', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
const commonFiles = files.filter((file) => file.match(/common.+\.js$/))
const commonContent = fs.readFileSync(path.join(projectPath, 'dist', commonFiles[0])).toString()
expect(commonFiles).not.to.be.empty
expect(commonContent).not.to.have.string('dependencyA')
expect(commonContent).not.to.have.string('dependencyB')
})

it('should have created a vendor.js file with the content of the node_modules dependencies', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
const vendorFiles = files.filter((file) => file.match(/vendor.+\.js$/))
const vendorContent = fs.readFileSync(path.join(projectPath, 'dist', vendorFiles[0])).toString()
expect(vendorFiles).not.to.be.empty
expect(vendorContent).to.have.string('dependencyA')
expect(vendorContent).to.have.string('dependencyB')
})
})

describe('project with two pages but one that is independent with vendor and common chunks enabled', () => {
const projectFixture = path.join(__dirname, '../fixtures/project-with-independent-page')
beforeEach(function () {
fs.copySync(projectFixture, projectPath, { overwrite: true })
return sagui({ projectPath, action: actions.BUILD })
})

it('should have created a common.js file without the content of the node_modules dependencies, but with the shared content', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
const commonFiles = files.filter((file) => file.match(/common.+\.js$/))
const commonContent = fs.readFileSync(path.join(projectPath, 'dist', commonFiles[0])).toString()
expect(commonFiles).not.to.be.empty
expect(commonContent).not.to.have.string('dependencyA')
expect(commonContent).not.to.have.string('dependencyB')
expect(commonContent).to.have.string('shared')
})

it('should have created a vendor.js file with the content of the node_modules dependencies', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
const vendorFiles = files.filter((file) => file.match(/vendor.+\.js$/))
const vendorContent = fs.readFileSync(path.join(projectPath, 'dist', vendorFiles[0])).toString()
expect(vendorFiles).not.to.be.empty
expect(vendorContent).to.have.string('dependencyA')
expect(vendorContent).to.have.string('dependencyB')
})

it('should include all dependencies and shared code in the independent page', () => {
const files = fs.readdirSync(path.join(projectPath, 'dist'))
const aboutFiles = files.filter((file) => file.match(/demo.+\.js$/))
const aboutContent = fs.readFileSync(path.join(projectPath, 'dist', aboutFiles[0])).toString()
expect(aboutContent).to.have.string('dependencyA')
expect(aboutContent).to.have.string('dependencyB')
expect(aboutContent).to.have.string('shared')
})
})
})

describe('project with duplicated transient dependencies and colliding node_modules', () => {
const projectWithNodeModules = path.join(__dirname, '../fixtures/project-with-node-modules')
beforeEach(function () {
Expand Down
Loading

0 comments on commit 5884302

Please sign in to comment.