Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added .babelrc file, so testing now works #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
presets: ["@babel/preset-env", "@babel/preset-react"]
}
76 changes: 76 additions & 0 deletions __tests__/enzyme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import { configure, shallow } from 'enzyme';
// import sinon from 'sinon';
import Adapter from 'enzyme-adapter-react-16';
// import CreateSchool from '../client/components/CreateSchool';
// import EventLanding from '../client/components/EventLanding';
import Classinfo from '../client/components/Classinfo';

configure({ adapter: new Adapter() });

describe('React unit tests', () => {
describe('Classinfo check', () => {
let wrapper;
const props = {
name: 'COMP101',
subject: 'Javascript Fundamentals',
};
beforeAll(() => {
wrapper = shallow(<Classinfo {...props} />);
});

it('Renders a <p> tag with the label in bold', () => {
expect(wrapper.type()).toEqual('div');
// expect(wrapper.text()).toEqual('Mega: Markets');
// expect(wrapper.find('strong').text()).toMatch('Mega');
});
});



})

// describe('CreateSchool', () => {
// // let wrapper;
// // beforeAll(() => {
// // wrapper = mount(<CreateSchool { ...props}/>)
// // })

// it('should submit event when submit is clicked', () => {
// const callback = sinon.spy();
// const wrapper = mount((
// <div className="schoolForm">
// <form onSubmit={handleSubmit(onSubmit)}>
// <label>Name</label>
// <input name="school_name" placeholder="School Name" ref={register} />

// <label>Location</label>
// <input name="school_location" placeholder="School Location" ref={register} />

// <input type="submit"></input>
// </form>
// </div>
// ),
// wrapper.find('[type="submit"]').get(0).click()
// expect(callback).to.have.been.called();
// )
// })
// // const props = {
// // school_name: "Penn State",
// // school_location: "State College"
// // };



// })
// })

/*
// POSSIBLE ENZYME REACT TEST
// Check if the shallow render matches

test("should render correctly", () => {
const wrapper = shallow(<CountDown startTime={30} />).toJSON();
expect(toJson(wrapper)).toMatchSnapshot();
});
*/
2 changes: 1 addition & 1 deletion build/bundle.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "file-tree:",
"main": "index.js",
"scripts": {
"test": "jest --verbose",
"start": "cross-env NODE_ENV=production node server/server.js",
"build": "cross-env NODE_ENV=production webpack",
"dev": "cross-env NODE_ENV=development concurrently \"webpack serve\" \"nodemon server/server.js\""
Expand All @@ -17,18 +18,25 @@
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-syntax-jsx": "^7.12.1",
"@babel/plugin-transform-react-jsx": "^7.12.12",
"@babel/preset-env": "^7.12.10",
"@babel/preset-react": "^7.12.10",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"cross-env": "^7.0.3",
"css-loader": "^5.0.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"enzyme-to-json": "^3.6.1",
"file-loader": "^6.2.0",
"jest": "^26.6.3",
"nodemon": "^2.0.6",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.10.3",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0",
"file-loader": "^6.2.0",
"url-loader": "^4.1.1"
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"axios": "^0.21.1",
Expand Down
67 changes: 34 additions & 33 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
const path = require("path");

module.exports = {
entry: './client/index.js',
entry: "./client/index.js",
output: {
path: path.resolve(__dirname,"./build"),
filename:'bundle.js'
path: path.resolve(__dirname, "./build"),
filename: "bundle.js",
},
mode: process.env.NODE_ENV,
module: {
rules: [
{
test: /jsx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
}
rules: [
{
test: /jsx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["@babel/plugin-transform-react-jsx"],
},
{
test: /css?$/,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
],
},
{
test: /\.jpg$/,
use: 'url-loader'
},
]
},
},
{
test: /css?$/,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
],
},
{
test: /\.jpg$/,
use: "url-loader",
},
],
},
resolve : {
extensions: ['.js', '.jsx']
resolve: {
extensions: [".js", ".jsx"],
},
devServer: {
publicPath: '/build/',
contentBase: path.join(__dirname, 'public/'),
port: 8080
}
publicPath: "/build/",
contentBase: path.join(__dirname, "public/"),
port: 8080,
},
};